add instant validation for rating
This commit is contained in:
parent
99ae5fd016
commit
5706dfaae8
@ -43,7 +43,7 @@ import {ErrorMsgComponent} from "./error-msg.component";
|
|||||||
<br>
|
<br>
|
||||||
<label for="rating">Rating</label>
|
<label for="rating">Rating</label>
|
||||||
<br>
|
<br>
|
||||||
<input id="rating" type="number" formControlName="rating" min="0" max="5">
|
<input id="rating" type="number" formControlName="rating">
|
||||||
<app-error-msg [msg]="errorMsgs['rating']"></app-error-msg>
|
<app-error-msg [msg]="errorMsgs['rating']"></app-error-msg>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
@ -103,6 +103,18 @@ export class EditHotelComponent implements OnInit {
|
|||||||
|
|
||||||
control?.valueChanges?.pipe(debounceTime(1000)).subscribe(() => {this.setErrorMessage(controlName, control)});
|
control?.valueChanges?.pipe(debounceTime(1000)).subscribe(() => {this.setErrorMessage(controlName, control)});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.form.controls['rating'].valueChanges.subscribe((value: number | null) => {
|
||||||
|
if (value === null) {
|
||||||
|
this.errorMsgs['rating'] = this.validationErrors['required'];
|
||||||
|
} else if (value < 0) {
|
||||||
|
this.errorMsgs['rating'] = this.validationErrors['min'];
|
||||||
|
} else if (value > 5) {
|
||||||
|
this.errorMsgs['rating'] = this.validationErrors['max'];
|
||||||
|
} else {
|
||||||
|
this.errorMsgs['rating'] = '';
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user