Привет, разбираюсь с валидацией, столкнулся с проблемой, используя встроенный емайл-валидатор в форме(formGroup) - он не работает.
<form [formGroup]="myForm" (ngSubmit)="onSubmit(f.value)" >
<input type="username" class="username" placeholder="NAME" name="username" [formControl]="myForm.get('username')" [(ngModel)]="username" >
<input type="username" class="username surname" placeholder="SURNAME" name="surname" [formControl]="myForm.get('surname')" [(ngModel)]="surname"><br>
<input type="email" class="mail" email name="emailField" [(ngModel)]="email" #emailField="ngModel">
<div class="emailinvalid" *ngIf="emailField.invalid && emailField.touched">
<span *ngIf="emailField.hasError('email')">
Please enter the correct email, this email not valid.
</span>
</div>
<br>
<textarea name="mesasge" class=" comment" placeholder="MESSAGE" cols="60" rows="8" name="comment" [formControl]="myForm.get('message')" [(ngModel)]="message"></textarea><br>
<button type="submit" class="sendbutton" [disabled]="!myForm.valid">SEND</button>
</form>
А здесь тс-код:
export class ContactComponent {
myForm: FormGroup;
email: string;
username: string;
surname: string;
message: string;
constructor(fb: FormBuilder) {
this.myForm = fb.group({
'username': ['', Validators.required],
'surname': ['', Validators.required],
'message': ['', Validators.required],
});
}
onSubmit(value: string): void {
console.log('you submitted value: ', value);
}
}