I want to display dialog box when validation fails.
currently i used formBuilder for validate the form but using this i couldn’t know how to display error message in dialogbox.
code that i used
constructor(private navController: NavController, private fb: FormBuilder,private service: WebService) {
this.authForm = fb.group({
'username': ['', Validators.compose([Validators.required, Validators.minLength(3)])],
'password': ['', Validators.compose([Validators.required, Validators.minLength(3)])]
});
}
html code
<ion-content class="home" padding>
<form [ngFormModel]="authForm" (ngSubmit)="onSubmit(authForm.value)">
<ion-item [class.error]="!username.valid && username.touched">
<ion-label floating>Username</ion-label>
<ion-input type="text" value={{userValue}} [ngFormControl]="username"></ion-input>
</ion-item>
<div *ngIf="username.hasError('required') && username.touched"
class="error-box">* Username is required!</div>
<div *ngIf="username.hasError('minlength') && username.touched"
class="error-box">* Minimum username length is !</div>
<ion-item [class.error]="!password.valid && password.touched">
<ion-label floating>Password</ion-label>
<ion-input type="password" value = {{pwdValue}} [ngFormControl]="password" ></ion-input>
</ion-item>
<div *ngIf="password.hasError('required') && password.touched"
class="error-box">* Password is required</div>
<div *ngIf="password.hasError('minlength') && password.touched"
class="error-box">* Minimum password length is 3!</div>
<br/><br/>
<ion-item>
<ion-label>Remember Me</ion-label>
<ion-checkbox [(ng-model)]='isChecked' ng-change='checkedOrNot(isChecked)' checked ={{isChecked}}></ion-checkbox>
</ion-item>
<br/><br/>
<button type="submit" class="custom-button" [disabled]="!authForm.valid" block>Submit</button>
</form>
</ion-content>