Angular 2 Forced Custom Keyboard Testing

I have this code:

this.form = fb.group({
        username: ['', Validators.compose([Validators.required])],
        fullName: ['', Validators.compose([Validators.required])],
        password: ['', Validators.compose([Validators.required])],
        confirmPassword: ['', Validators.required],
    }, {validator: matchingPasswords('password', 'confirmPassword')});

matchingPasswords:

export function matchingPasswords(passwordKey: string, passwordConfirmationKey: string) {
return (group: FormGroup) => {
    let password = group.controls[passwordKey];
    let passwordConfirmation = group.controls[passwordConfirmationKey];
    if (password.value !== passwordConfirmation.value) {
        return passwordConfirmation.setErrors({mismatchedPasswords: true})
    }
}

}

HTML:

<div class="form-group">
        <input [formControl]="confirmPassword" class="form-control checking-field" type="password">
        <span class="help-block text-danger" *ngIf="form.get('password').touched && form.get('password').hasError('required')">
</div>
<div class="form-group">
        <input class="custom-control-input checkbox-main" type="checkbox" [(ngModel)]="policyButtonValue" [ngModelOptions]="{standalone: true}" ngDefaultControl>
        <span class="custom-control-indicator"></span>
</div>

it is functional and works fine, but I have a special use case that needs to be fixed.

  • click in the first password field.
  • enter password, for example: "foo"
  • click in the password confirmation field.
  • tpye in the same, for example .: "foo" enter image description here up to this point no problem.
  • enter something else in the password confirmation field, for example: "foobar" (currently the validator shows that there is an error) enter image description here
  • click in the password field
  • , : "foobar" - , ... enter image description here , matchPassword keyup, ?
+4
1

else:

if (password.value !== passwordConfirmation.value) {
    passwordConfirmation.setErrors({mismatchedPasswords: true})
}
else {
    passwordConfirmation.setErrors(null);
}
+3

Source: https://habr.com/ru/post/1672231/


All Articles