jQuery Validation Easy Custom Validation Exceptions


Here’s a method I just used to add some very / arbitrarily complex validation logic to your existing jQuery Validation form.

The use case was that my form, depending on arbitrary third party ajax calls, could contain custom invalid fields in ways that would be difficult to carry out through the framework itself.

Why not offload all of that logic to some third party, like the server, and then have some javascript simply set data attributes on the form elements which mark it as "invalid"?

That’s exactly what I did.

For example, my server could claim that the ship_state field is invalid for various reasons. All my AJAX needed to do was set a data attribute on that field called `custom-validator-exception`, with the value as the error message, and the validation framework seamlessly incorporates that error into the workflow.




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s