nghuuphuoc/bootstrapvalidator — pull request #480 by mbezhanov (2014-07-09 10:19:06+00:00)
Title: Verbose

Hello Nguyen,

This is another feature I had to develop in order to customize the plugin for one of the projects I was working on recently, and again - I thought I could share it with the community, so if you consider it's useful - it can become available for everyone.

I had a very huge form, with many fields in the form relying on multiple validators. For this particular form, I didn't like the clutter that multiple validation error messages on a field were causing. When I digged deeper into your code, I saw that when a field has multiple validators associated with it, you are processing them all one after another, regardless of the response of the preceding validators. I thought for a larger form with many fields and many validators, it may also be beneficial in terms of performance to instruct the plugin to terminate on the very first validation error it encounters for each field, and directly proceeding to validating the next one, thus saving some resources.

JavaScript execution is pretty fast and I know the performance isn't a big deal in that case, my primary goal with this feature was to enable the option of having the plugin display only one error message at time for each field.

I have achieved this by introducing the 'verbose' option, which default to 'true'. If a developer decides, they want to see one message at a time for each field in their form, they can set 'verbose' to 'false', when initializing the plugin.

I want to add, that I haven't enabled this option for the remote validator - I don't know if I should have done that, but from the implementation of the remote validator, it seems to me that it isn't expected to be combined with other validators, when used on a field - am I correct?

Well, I hope this feature is useful for the community, or if it isn't, but you think it has some potential - let me know what changes I need to apply.

Best regards,
Marin