Please cast your vote for a proposed change to validation@v2

Though a tad bit late to the party, I want to point out couple of things.

Firstly the changrOrEVENT trigger (where EVENT is blur or focusout) does not trigger the validation until the field is either validated by one of the EVENT-triggered validation or manual validation. Once the field is validated, every change in the field will trigger the validation. Apart from this, also note that the EVENTwill not trigger validation if the field is not dirty; for example, you focus the field and then leave it without change, the validation won’t be triggered as the field is not dirty. This change of behavior has been introduced in aurelia-validation@2.x. Here are the relevant resources in case you have missed it:

This serves 2 purposes:

  • Reduce yelling at user when she/he has not finished typing the input, and thereby delaying the punishment.
  • If the field has already failed validation, and user is making correction (changing the field value), provide early feedback by validating eagerly, and thereby reward early.

The motivation behind this change is to provide better UX. BTW the originally @jods4 told me about this idea of “Reward early, punish later”, and I took that to heart.

Anyway, coming back to the issue at hand. It is clear that using changeOrEVENT trigger won’t necessarily provide feedback for every change and the validation is triggered pragmatically. In comparison to the change trigger, this should reduce triggering the expensive validation rules needlessly.

Naturally, the same behavior is also incorporated in Aurelia 2. As blur is the default trigger, used in aurelia-validation, focusout has been kept as the default trigger in Aurelia2 validation (as the event focusout works for larger use-cases, and quite well supported by browsers). However, with blur or focusout there is no dual behavior like changeOrEVENT trigger, and the validation is triggered whenever the event is raised(in accordance with aurelia-validation).

Therefore, in the light of the changed behavior of the changeOrEVENT trigger , the question at hand boils down to whether focusout being the default trigger serves better than the changeOrEVENT trigger, or not?

I am bit biased to say that thechangeOrFocusout trigger serves better as the default trigger. However, it really depends on the use-case at hand. But whatever the OOTB default trigger is, you can always change that as per your need when you register the plugin (refer the Aurelia2 doc).

I hope this clarifies some of the questions raised.

2 Likes