lcoq/ember-validations

Support to return upon first error

Opened this issue · 6 comments

Would it be possible to exit validation execution upon first error instead of executing all the registered validations of an attribute, as in some scenarios it is not required to show all the messages of an attribute in one go like scenarios where error messages are displayed next to the input control inline, please correct me if this kind of support is already present and your contribution to this framework is very much appreciated.

lcoq commented

I understand the idea, but I wonder why do you want this feature.
If you just wants to show only one message, you could use user.get('validationErrors.age.messages.firstObject'), it will then return the first error message, and you do not have to care about the others.

age: {
                    presence: true,
                    numericality: {
                        moreThanOrEqualTo: 21,
                        lessThan: 99
                    }
       }

Lets consider a scenario where all the form errors are displayed in a common summary container by using 'validationErrors.fullMessages' helper, in the above example age has got presence and number validations and it displays both the errors in one go and my requirement is not to show the numericality errors until presence validator succeeds, is there any possibility to achieve this in the current framework?

lcoq commented

Sorry to respond so late, I am currently really busy.

Indeed, the library does not allow to do this kind of things easily.
I'll try to think about its implementation soon.

lcoq commented

If you're using ember-data, you could also take a look at https://github.com/dockyard/ember-validations which seems pretty good.

Thanks for your valuable response and will update you if I can make any progress in this direction.