jQuery Validate plugin: Can using the "depends" tag return an int? -
here example of rule declaration in rules object:
myfieldobj: { maxlength: { depends: function(element) { if($("#intranetapplication").is(":checked") == true) { return 32; } else if($("#internetapplication").is(":checked") == true) { return 25; } } } }
basically, code setting max length of myfieldobj validated based on user choice of question. however, code not seem work. know can return boolean values using code (e.g):
myfieldobj: { maxlength: { depends: function(element) { if($("#intranetapplication").is(":checked") == true) { return true; } else if($("#internetapplication").is(":checked") == true) { return false; } } } }
but work integers well?
just remove depends
property , use function method's parameter...
myfieldobj: { maxlength: function(element) { if ($("#intranetapplication").is(":checked")) { return 32; } else if ($("#internetapplication").is(":checked")) { return 25; } } }
also since .is()
returns boolean, there's no need compare true
.
demo: jsfiddle.net/931ach1g/
Comments
Post a Comment