Ankur
Ankur

Reputation: 740

Aurelia Validation on updateTrigger and validationTrigger

Recently validation files has been updated in Aurelia.

I have already implemented some validations as shown in the below links:

I need to implement a functionality in which input field is validated on blur as well as while typing.

For example:

An input field is a required field which accepts minimum 5 character and maximum 10.

Now input field is empty and has lost focus then validation for required field is triggered, now the user comes back to input and start typing then required field validation is gone and validation for minimum and maximum are triggered(or validated as use types).

Please suggest how should I proceed.

Upvotes: 1

Views: 466

Answers (3)

Kitrod
Kitrod

Reputation: 11

The default validationTrigger for the validation controller is on blur. If you want to override this to "blur or change", this can be done by importing the validateTrigger from aurelia-validation and setting the validation trigger for your validation controller.

this.controller.validateTrigger = validateTrigger.changeOrBlur;

This can also be accomplished in the markup by specifying the trigger like this.

<input type="text" value.bind="value & validateOnChangeOrBlur">

Aurelia Validation Docs

Upvotes: 0

msokrates
msokrates

Reputation: 188

Maybe this would help you achieve what you want:

this.controller.validateTrigger = validateTrigger.changeOrBlur;

Upvotes: 1

manza
manza

Reputation: 322

You should trigger validation controller on change (default is on blur). You have to set your validation controller to be able to do that with:

this.controller.validateTrigger = validateTrigger.change;

Upvotes: 0

Related Questions