Hello to everyone,
I’m using Ionic 3 form validation. Everything works, but I want to display an error message if the required field is empty. Is there a way to do this?
Thanks in advance.
Example TS code:
import { Validators, FormBuilder, FormGroup } from ‘@angular/forms’;
private todo : FormGroup;
constructor(private view: ViewController,private formBuilder: FormBuilder, private auth: AuthServiceProvider) {
this.todo = this.formBuilder.group({
name: [’’, Validators.required],
surname: [’’]
});
}
Html file code:
<form [formGroup]="todo" (ngSubmit)="postData()"><ion-item>
<ion-label>
Müşteri Adı
</ion-label>
<ion-input type="text" formControlName="name" [(ngModel)]="todo.name" name="name" placeholder=""></ion-input>
</ion-item>
<ion-item>
<ion-label>
Müşteri Soyadı
</ion-label>
<ion-input type="text" formControlName="surname" [(ngModel)]="todo.surname" name="surname" placeholder=""></ion-input>
</ion-item>
<div class="spacer" style="height:30px;"></div>
<button type="submit" [disabled]="!todo.valid" ion-button block>
Kaydet
</button>
</form>