iLemming
iLemming

Reputation: 36166

manually updating validity of the elements

I'm using jquery.validate and jquery.validate.unobtrusive and I wonder how can I manually make certain elements "valid" or "invalid" from the javascript code?

I'm trying to modify $('form').validate() properties like successList invalid and errorMap but it still doesn't change $('form').valid()'s behavior, so apparently I'm not doing that right.

Upvotes: 0

Views: 380

Answers (1)

Sparky
Sparky

Reputation: 98728

Quote OP:

"I wonder how can I manually make certain elements "valid" or "invalid" from the javascript code?"

Only the assigned rules along with the user-entered data can "make" an input element valid or invalid. There is no method for you to over-ride this, otherwise there's really no point in using the plugin.


However, you can dynamically change any of the rules using the .rules('add') and .rules('remove') methods.


EDIT based on OP's comment:

let's say your input field needs a custom validation and depends on other element's value e.g. dropdown

Use the built-in method called addMethod to turn your custom function into a custom rule for the plugin to use.

Upvotes: 1

Related Questions