Mam następujący Kątowymi 2 postaci:kątowa walidacji 2 formy, MINLENGTH walidator nie działa
<register>
<form [ngFormModel] = "registrationForm">
<div class = "form-group">
<label class = "control-label" for="email">Email</label>
<input class = "form-control" type="email" id="email" ngControl="email" #email="ngForm">
</div>
<div *ngIf = "email.touched && email.errors">
<div *ngIf = "!email.errors.required && email.errors.underscoreNotFound" class = "alert alert-danger">
<span>Underscore is required</span>
</div>
<div *ngIf = "email.errors.required" class = "alert alert-danger">
<span>Email is required</span>
</div>
</div>
<div class = "form-group">
<label class = "control-label" for="password">Password</label>
<input class = "form-control" type="password" id="password" ngControl="password" #password="ngForm">
</div>
<div *ngIf = "password.touched && password.errors">
<div *ngIf = "password.errors.minLength && !password.errors.required" class = "alert alert-danger">
<span>Password should contain 6 characters</span>
</div>
<div *ngIf = "password.errors.required" class = "alert alert-danger">
<span>Password is required</span>
</div>
</div>
</form>
</register>
To jest mój Komponent gdzie wdrożyliśmy weryfikatorów:
import {Component} from '@angular/core';
import {Control, ControlGroup, FormBuilder, Validators} from '@angular/common';
import {CustomValidator} from './CustomValidator';
@Component({
selector: 'register',
templateUrl: './app/authentication/register_validation/register.html',
})
export class RegisterComponent{
registrationForm: ControlGroup;
constructor(formBuilder:FormBuilder)
{
this.registrationForm = formBuilder.group({
email: ['',Validators.compose([Validators.required, CustomValidator.underscore])],
password: ['',Validators.compose([Validators.required,Validators.minLength(6)])]
});
}
}
W tej formie email
Pole działa poprawnie dla obu weryfikatorów, tzn. gdy niczego nie wpisuję, daje komunikat "Email is required"
, kiedy zaczynam pisać coś, daje on komunikat "Underscore is required"
, a po wpisaniu "_"
wszystkie komunikaty o błędach znikają. Jednak gdy spróbuję zastosować takie 2 sprawdzania poprawności w polu password
, to nie działa. Gdy nie wpisuję hasła, pojawia się komunikat: "Password is required"
. Ale kiedy wpisuję coś mniej niż 6 znaków, wiadomość nie pojawia się wcale. Co jest nie tak w tym kodzie?
Czy możesz utworzyć https://plnkr.co za pomocą kodu –
Również używasz wersji niższej niż RC3. który jest przestarzały. Wypróbuj nową wersję RC3 –
może polecić tę odpowiedź http://stackoverflow.com/a/38092249/5868331 – mayur