Ignored keys for form changed in dialogs
This commit is contained in:
parent
c71a4995a6
commit
3724a6c0b6
@ -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 {
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user