0

I need to enable jquery validation on readonly fields that is disabled by default in jquery validator 1.13.0. Following is my code:

jQuery(".profile-forms").validate({
        errorElement: "span",
        errorClass: "error",
                errorPlacement: function(error, element) {
                    if(element[0])
                    {
                        jQuery('#'+element[0].id+'-error').replaceWith(error);
                    }
                },
        rules: {
            first_name:{
                required:true,
                                restrictEmail:true,
                                noDigit: true
            },
            last_name:{
                required:true,
                                restrictEmail:true,
                                noDigit: true
            },
                        location: {
                            required:true,
                            restrictEmail:true,
                            restrictPhoneNumber:true
                        },
                        city: {
                            required:true,
                        },
                        state: {
                            required:true,
                        }
    });

I am using jQuery Validator 1.13.0. Kindly Help!! I need to apply required validation on 'City' and 'State' fields

Sparky
  • 98,165
  • 25
  • 199
  • 285
Muhammad Raza
  • 424
  • 5
  • 22
  • You can't. `readonly` fields cannot be validated, because it makes no sense. The purpose of validation is to let the user know he's entered something wrong so that he can make a correction. The user cannot edit the data, so there is no reason to validate it. Otherwise, you'll need to explain your idea much better and include the relevant HTML markup in the OP. – Sparky Apr 02 '15 at 16:06
  • I am definetly not a PHP expert, but I think you can use PHP to validate readonly input fields. – Michelangelo Apr 02 '15 at 16:10
  • @Mikey, what does PHP have to do with a question about client-side validation in jQuery? – Sparky Apr 02 '15 at 16:10
  • Well, for all I know there is no way to validate a readonly input field on the client side. If OP really wants a validation server side techniques might come in handy. It was just a hint for OP... – Michelangelo Apr 02 '15 at 16:14
  • @Raza Take a look at this, it's hacky but doable apperently: http://stackoverflow.com/questions/26838839/how-can-i-enable-jquery-validation-on-readonly-fields – Michelangelo Apr 02 '15 at 16:16

0 Answers0