Adding client side validation to dynamically loaded content

Apr 24, 2012 at 11:37 PM
Edited Apr 25, 2012 at 3:15 PM

Hello,

I'm looking to attach a validator to a dynamically (Javascript) loaded field. Normally, I would do this:

$("#Hours").rules("add", { range: [0, 1000], is: ["MinimumHours", "GreaterThanOrEqualTo"], messages: { range: "Hours must be between 0 and 1000.", is: "Hours does not meet minimum requirement."} });

 

But this doesn't seem to work for the Foolproof validation methods...

Any ideas on where to go from there?

Apr 25, 2012 at 3:14 PM

I got it... looks like there is a kludge in the jquery.validate library for range specifically (and a few others) so that you can pass in a simple array.

For custom adapters, like the Foolproof validation library, you have to specify what values you are passing in, which means passing in an object instead:

$("#Hours").rules("add", { range: [0, 1000], is: { dependentproperty: "MinimumHours", operator: "GreaterThanOrEqualTo" }, messages: { range: "Hours must be between 0 and 1000.", is: "Hours does not meet minimum requirement."} });