Hi,
I am trying to validate an optional field but it is validated every
time either it is included or not on the form.Please help me that how
can i validate optional fields using jQuery validator.
Regards,
Himanshu Singh
On Jan 26, 3:18 pm, Jörn Zaefferer joern.zaeffe...@googlemail.com
wrote:
Jörn,
many thanks - this has worked wonderfully!
The only remaining question I have is as follows:
messages generated by specified validation methods clear automatically
after the form field gets updated:
so in the chain of required,digits,minlength,maxlength each message
comes and goes as
Ah, good question. Try this:
$.validator.addMethod(dynamic_check, function(value, element, param) {
if(incorrect(value, param)){
this.settings.messages[element.name].dynamic_check = some
dynamic message
+ dynamicValue;
return false;
}
}, whatever));
That sets the new
Try this workaround - update validator.settings.messages[element.name]
with the appropiate value inside your validation method:
$.validator.addMethod(dynamic_check, function(value, element, param) {
if(incorrect(value, param)){
this.settings.messages[element.name] = some dynamic
You can use $.format to create dynamic messages, but that works only
when the dynamic part is specified as a parameter.
$.validator.addMethod(dynamic_check, function(value, element, param) {
if(incorrect(value, param)){
return false;}
}, $.format('dynamic message goes here with
Thanks Jörn,
but is there a way to change param dynamically during JS runtime?
As example in your custom-methods-demo.html I'd like 11 to be a
function of value ...
math: {equal: 11}
In my barcoding example, I'd like not only tell user that barcode
number is wrong, but also what the check
6 matches
Mail list logo