Skip to content

Commit

Permalink
IKC-416 Validate user group form - no white spaces only
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Belke authored and Piotr Belke committed Oct 14, 2024
1 parent 3f753e6 commit 588a236
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {FormGroup, NG_VALUE_ACCESSOR} from '@angular/forms';
<mat-error class="error" *ngIf="hasError('unique')">
Field value is not unique
</mat-error>
<mat-error class="error" *ngIf="hasError('noOnlyWhitespace')">
Field value is not correct
</mat-error>
</ng-container>
</div>
`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export class UserGroupFormComponent implements OnInit, OnDestroy {
userGroupForm: FormGroup = new FormGroup({
id: new FormControl(),
code: new FormControl('', {
validators: [Validators.required],
validators: [Validators.required, this.noOnlyWhitespace],
asyncValidators: this.isUserGroupCodeUnique(),
updateOn: 'change'
}),
name: new FormControl('', [Validators.required]),
name: new FormControl('', [Validators.required, this.noOnlyWhitespace]),
});
viewMode: ViewMode = ViewMode.CREATE;
ViewMode: typeof ViewMode = ViewMode;
Expand Down Expand Up @@ -149,4 +149,12 @@ export class UserGroupFormComponent implements OnInit, OnDestroy {
: of(null);
};
}

noOnlyWhitespace(control: FormControl): ValidationErrors | null {
if (control.value) {
const isWhitespace = (control.value || '').trim().length === 0;
return !isWhitespace ? null : {'noOnlyWhitespace': true};
}
return null;
}
}

0 comments on commit 588a236

Please sign in to comment.