add better validation to forms
This commit is contained in:
parent
6e5eadd3a2
commit
a6829fc3f5
@ -3,11 +3,11 @@ import { HotelFormComponent } from './hotel-form/hotel-form.component';
|
||||
import { HotelDetailsComponent } from './hotel-details/hotel-details.component';
|
||||
|
||||
export const formGuard: CanDeactivateFn<HotelFormComponent | HotelDetailsComponent> = (component: HotelFormComponent | HotelDetailsComponent, currentRoute, currentState, nextState) => {
|
||||
console.log(component)
|
||||
if (component instanceof HotelFormComponent && component.form?.dirty) {
|
||||
return confirm('You have unsaved changes. Do you really want to leave?');
|
||||
}
|
||||
else if (component instanceof HotelDetailsComponent && component.hotelForm?.form?.dirty) {
|
||||
const hasUnsavedChanges =
|
||||
(component instanceof HotelFormComponent && component.form?.dirty) ||
|
||||
(component instanceof HotelDetailsComponent && component.hotelForm?.form?.dirty);
|
||||
|
||||
if (hasUnsavedChanges) {
|
||||
return confirm('You have unsaved changes. Do you really want to leave?');
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user