Skip to content

Commit

Permalink
frontend #35: fix validation errors in userForm bio field
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingbeat committed Apr 26, 2024
1 parent 9bffa89 commit 12ea7d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<div>
<div style="padding: 6px" *ngIf="errors()?.['required']">
<ion-text color="danger">{{ field() }} is required.</ion-text>
</div>
<div style="padding: 6px" *ngIf="errors()?.['maxlength']">
<ion-text color="danger">{{ field() }} must be at most 20 characters long.</ion-text>
</div>
<div *ngIf="errors()?.['required']" style="padding: 6px">
<ion-text color="danger">{{ field() }} is required.</ion-text>
</div>
<div *ngIf="errors()?.['maxlength']" style="padding: 6px">
<ion-text
color="danger">{{ field() + " must be at most " + errors()?.['maxlength']['requiredLength'] + " characters long." }}
</ion-text>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common';
import { Component, input } from '@angular/core';
import { Component, effect, input } from '@angular/core';
import { ValidationErrors } from '@angular/forms';
import { IonText } from '@ionic/angular/standalone';

Expand All @@ -11,7 +11,11 @@ import { IonText } from '@ionic/angular/standalone';
imports: [IonText, CommonModule]
})
export class UserFormExceptionsComponent {
constructor() {}
constructor() {
effect(() => {
console.error(this.errors());
});
}

errors = input<ValidationErrors | null>();
field = input<string>();
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/user-form/user-form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ <h2>{{ formTitle() }}</h2>
</ion-item>
@if (userForm.controls.bio.touched && userForm.controls.bio.invalid) {
<app-user-form-exceptions
[field]="'bio'"
[errors]="userForm.controls.bio"
[field]="'Bio'"
[errors]="userForm.controls.bio.errors"
></app-user-form-exceptions>
}
<div>
Expand Down

0 comments on commit 12ea7d2

Please sign in to comment.