add better validation to forms

This commit is contained in:
Jan-Marlon Leibl 2024-12-03 09:23:50 +01:00
parent 6e5eadd3a2
commit a6829fc3f5

View File

@ -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?');
}