$.validator.setDefaults({
ignore: ':hidden, [readonly=readonly]'
});
The default for the ignore
parameter is ":hidden"
. By resetting the default using the above code, you make sure that jquery validate still does not act on hidden form elements, but also does not act on elements that have a readonly="readonly"
attribute.
Reply to comments
That sounds odd, you may have to post some code to get more help. One thing you could try to remove the validation errors is to manually validate the form when you toggle the readonly attribute, something like this perhaps:
$('#the_text_box').attr('readonly', 'readonly');
$.validator.setDefaults(':hidden');
$('form').valid();
$.validator.setDefaults(':hidden, [readonly=readonly]');
You could also do something similar during the initial page load to avoid the instant validation error messages.
$.validator.setDefaults(':hidden, [readonly=readonly]');
$('form').valid();