Field Check on Burur with Aurelia

I use Aurelia and Typescript to create a web page. I have a simple login form and I would like to check the correct email and user password.

I use Aurelia validation and by default it checks the contents of my input every time it changes, which can be annoying. (for example: receiving an error message indicating that the letter is not valid when you did not even type it). Therefore, I would like to do onBlur validation instead (when the focus on the input is lost) and when the user clicks the "Login" button.

Here is my code:

login.html

<template>
<section>
    <div class="container col-lg-12">
        <div class="col-md-4 col-md-offset-4 centered">
            <h2 t="signin_sign_in"></h2>
            <form role="form" submit.delegate="login()" validate.bind="validation">
                <br if.bind="errors" />
                <div if.bind="errors" repeat.for="error of errors" class="alert alert-danger">
                    <h4 repeat.for="message of error">${message}</h4>
                </div>
                <div class="form-group">
                    <label class="control-label" t="signin_email_address"></label>
                    <input type="text" class="form-control" value.bind="email">
                </div>
                <div class="form-group">
                    <label class="control-label" t="signin_password"></label>
                    <input type="password" class="form-control" value.bind="password">
                </div>
                <button type="submit" class="btn btn-primary" t="signin_sign_in"></button>
            </form>
        </div>
    </div>
</section>
</template>

login.ts

@autoinject()
export class Login {
  email: string;
  password: string;
  router: Router;
  application: ApplicationState;
  accountService: AccountService;
  errors;
  validation;
  i18n: I18N;

constructor(router: Router, application: ApplicationState, accountService: AccountService, validation: Validation, i18n: I18N) {
    this.router = router;
    this.application = application;
    this.accountService = accountService;
    this.i18n = i18n;
    this.errors = [];

    this.validation = validation.on(this)
        .ensure('email')
            .isNotEmpty()
            .isEmail()
        .ensure('password')
            .isNotEmpty()
            .hasLengthBetween(8, 100);
}

navigateToHome(): void {
    this.router.navigate("/welcome");
}

login(): void {
    var __this = this;
    this.validation.validate()
        .then(() => this.accountService.signin(this.email, this.password, this.rememberMe)
            .then(result => {
                // Do stuff
            })
            .catch(error => {
                // Handle error
                }
            }));
}
}

My first thought was to add

& updateTrigger:'blur':'paste'

HTML, . , , . Chrome .

, ? ?

+4
1

, , , . Aurelia docs ( Validate Binding Behavior).

validateTrigger (, , OrBlur, ). validateTrigger , :

& validateOnBlur: DOM .
validateOnChange: , .
validateOnChangeOrBlur: DOM- .
validateManually: , .

0

All Articles