Skip to content

Commit

Permalink
dirty form fix for nested customFields
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaudiomv committed Nov 10, 2024
1 parent 703914c commit b6e578d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/resources/js/components/MeetingEditForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@
<div class="grid gap-4 md:grid-cols-2">
<div class="md:col-span-2">
<Label for={name} class="mb-2">{displayName}</Label>
<Input type="text" id={name} name={$data.customFields[name]} bind:value={$data.customFields[name]} />
<Input type="text" id={name} name={initialValues.customFields[name]} bind:value={initialValues.customFields[name]} />
{#if $errors.customFields?.[name]}
<Helper class="mt-2" color="red">
{$errors.customFields[name]}
Expand Down
18 changes: 15 additions & 3 deletions src/resources/js/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,21 @@ export function formIsDirty(initialValues: any, currentValues: any): boolean {
return true;
}
}
} else if (initialValues[key] !== currentValues[key]) {
isDirty.set(true);
return true;
}
// handle customFields
else if (typeof initialValues[key] === 'object' && initialValues[key] !== null) {
if (formIsDirty(initialValues[key], currentValues[key])) {
isDirty.set(true);
return true;
}
} else {
// Treat null and undefined as ''
const initial = initialValues[key] ?? '';
const current = currentValues[key] ?? '';
if (initial !== current) {
isDirty.set(true);
return true;
}
}
}
isDirty.set(false);
Expand Down

0 comments on commit b6e578d

Please sign in to comment.