Skip to main content

Posts

Showing posts from 2020

Reflecting server errors in Angular form validation

Here's some sample code that shows how to display server validation errors sent by a django-restframework REST server.

<form [formGroup]='form' (ngSubmit)="doChangePassword()"> <ion-item> <ion-label>{{ 'CURRENT_PASSWORD' | translate }}</ion-label> <ion-input formControlName="old_password" type="password"></ion-input> </ion-item> <ion-item class="ion-text-wrap ion-no-lines" *ngIf="form.controls.old_password.errors?.required && form.controls.old_password.dirty && form.controls.old_password.touched"> <ion-label color='danger' class="ion-no-margin" stacked>{{ 'FIELD_IS_REQUIRED' | translate }}</ion-label> </ion-item> <ion-item class="ion-no-lines" *ngFor="let errorMsg of form.controls.old_password.errors?.serverErrors"> <ion-label colo…