DEV Community

Daniel Barwikowski
Daniel Barwikowski

Posted on

Why jQuery unobtrusive validation sucks 😒

If you ever used jquery.validate then you might have used groups feature.

It allows you to group inputs so when one or more of them have invalid value, then one (and only one) error is displayed.

It's useful when you don't want to flood user with list of errors.
For example:

  • split date into three inputs: day, month and year.

Now, you might want to display error like: 'Date is incorrect, please verify and correct' whenever day, month or year is incorrect.

Without grouping you would have 3 errors is all 3 inputs have incorrect value
34-13-asdf.

It's easy to setup such validation in jQuery validate but it's not so easy to do with jQuery unobtrusive validation.

What is unobtrusive validation?

It's just a framework that allows you to setup validation with usage of data-val-*="" attributes.
It means that you don't have to write any js to setup form validation.
While it sound cool it's also limiting you with many options.

What is the problem? Just create new validator!

jQuery.validate checks if there is existing validator for element and returns existing validator skipping all configuration you might wanted to add.

Of course I could remove it and add new one but then you have to handle hooks and all common settings you (or someone) might have added...

Top comments (0)