Fix proclamation form fields not auto-filling on edit
Switch from initialized from prop to -synced values so form fields always populate when the record changes. Key the TipTap editor on record.id to force re-render.
This commit is contained in:
@@ -32,18 +32,23 @@
|
|||||||
if (record.id) dirty = true;
|
if (record.id) dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = $state(String(record.name ?? ''));
|
let name = $state('');
|
||||||
let solfeggioFrequencyId = $state(String(record.solfeggioFrequencyId ?? ''));
|
let solfeggioFrequencyId = $state('');
|
||||||
let subscriptionLevelId = $state(String(record.subscriptionLevelId ?? ''));
|
let subscriptionLevelId = $state('');
|
||||||
|
let parentCategoryId = $state('');
|
||||||
|
let categoryId = $state('');
|
||||||
|
|
||||||
let parentCategoryId = $state(
|
$effect(() => {
|
||||||
String(
|
name = String(record.name ?? '');
|
||||||
|
solfeggioFrequencyId = String(record.solfeggioFrequencyId ?? '');
|
||||||
|
subscriptionLevelId = String(record.subscriptionLevelId ?? '');
|
||||||
|
parentCategoryId = String(
|
||||||
record.parentCategoryId ??
|
record.parentCategoryId ??
|
||||||
(record.category as Record<string, unknown> | undefined)?.parentId ??
|
(record.category as Record<string, unknown> | undefined)?.parentId ??
|
||||||
''
|
''
|
||||||
)
|
);
|
||||||
);
|
categoryId = String(record.categoryId ?? '');
|
||||||
let categoryId = $state(String(record.categoryId ?? ''));
|
});
|
||||||
|
|
||||||
let parentOptions = $derived(categories.filter((c) => c.parentId === null));
|
let parentOptions = $derived(categories.filter((c) => c.parentId === null));
|
||||||
|
|
||||||
@@ -56,6 +61,8 @@
|
|||||||
parentCategoryId = target.value;
|
parentCategoryId = target.value;
|
||||||
categoryId = '';
|
categoryId = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let contentKey = $derived(record.id ?? 'new');
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form {action} method="POST" use:enhance oninput={markDirty}>
|
<form {action} method="POST" use:enhance oninput={markDirty}>
|
||||||
@@ -200,12 +207,14 @@
|
|||||||
>
|
>
|
||||||
Content
|
Content
|
||||||
</label>
|
</label>
|
||||||
<div id="field-content">
|
<div id="field-content">
|
||||||
|
{#key record.id}
|
||||||
<TipTap
|
<TipTap
|
||||||
initialContent={typeof record.content === 'string' ? record.content : ''}
|
initialContent={typeof record.content === 'string' ? record.content : ''}
|
||||||
name="content"
|
name="content"
|
||||||
/>
|
/>
|
||||||
</div>
|
{/key}
|
||||||
|
</div>
|
||||||
{#if fieldErrors.content}
|
{#if fieldErrors.content}
|
||||||
<p class="mt-1 text-xs text-red-600">{fieldErrors.content}</p>
|
<p class="mt-1 text-xs text-red-600">{fieldErrors.content}</p>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user