add validation for submit
This commit is contained in:
parent
2503c33005
commit
99ae5fd016
@ -107,7 +107,8 @@ export class EditHotelComponent implements OnInit {
|
||||
|
||||
submit() {
|
||||
if (!this.form.valid) {
|
||||
|
||||
this.showErrors();
|
||||
return;
|
||||
}
|
||||
|
||||
const hotel: Hotel = {
|
||||
@ -140,4 +141,15 @@ export class EditHotelComponent implements OnInit {
|
||||
setErrorMessage(controlName: string, control: AbstractControl) {
|
||||
this.errorMsgs[controlName] = Object.keys(control.errors ?? {}).map ((key) => this.validationErrors[key]).join(' ');
|
||||
}
|
||||
|
||||
private showErrors() {
|
||||
Object.keys(this.form.controls).forEach(controlName => {
|
||||
const control = this.form.get(controlName);
|
||||
if (!control) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setErrorMessage(controlName, control);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user