Ignored keys for form changed in dialogs

This commit is contained in:
Adina Țeudan 2024-09-23 22:23:02 +03:00
parent c71a4995a6
commit 3724a6c0b6
2 changed files with 8 additions and 2 deletions

View File

@ -22,6 +22,8 @@ export abstract class IqserDialogComponent<ComponentType, DataType = null, Retur
readonly data = inject<DataType>(MAT_DIALOG_DATA);
readonly dialog = inject(MatDialog);
readonly form?: FormGroup;
readonly ignoredKeys: string[] = [];
initialFormValue: Record<string, unknown> = {};
constructor(private readonly _editMode = false) {
@ -37,7 +39,7 @@ export abstract class IqserDialogComponent<ComponentType, DataType = null, Retur
}
get changed(): boolean {
return !this.form || hasFormChanged(this.form, this.initialFormValue);
return !this.form || hasFormChanged(this.form, this.initialFormValue, this.ignoredKeys);
}
get disabled(): boolean {

View File

@ -141,12 +141,16 @@ export function trackByFactory<T extends ITrackable<PrimaryKey>, PrimaryKey exte
return (_index: number, item: T): Id => item.id;
}
export function hasFormChanged(form: UntypedFormGroup, initialFormValue: Record<string, unknown>): boolean {
export function hasFormChanged(form: UntypedFormGroup, initialFormValue: Record<string, unknown>, ignoredKeys: string[] = []): boolean {
if (!form || !initialFormValue) {
return false;
}
for (const key of Object.keys(form.getRawValue())) {
if (ignoredKeys.includes(key)) {
continue;
}
const initialValue = initialFormValue[key];
const updatedValue = form.get(key)?.value;