Fix checklist item add: form value cleared before submission

The bind:value + onsubmit pattern caused the input to be empty when
enhance submitted the form. Replaced with post-submission DOM reset
so the value is intact during submission.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-07 10:53:16 +07:00
parent 1351b77034
commit cceba73785
2 changed files with 30 additions and 8 deletions
+15 -4
View File
@@ -11,7 +11,10 @@
let showLogForm = $state(false);
let showNewChecklist = $state(false);
let showImportChecklist = $state(false);
let newItemText: Record<string, string> = $state({});
function resetInput(formEl: HTMLFormElement) {
const input = formEl.querySelector('input[name="text"]') as HTMLInputElement;
if (input) input.value = '';
}
</script>
<svelte:head>
@@ -436,11 +439,19 @@
</div>
<!-- Add item -->
<form method="POST" action="?/addChecklistItem" use:enhance
onsubmit={() => { newItemText[checklist.id] = ''; }}
<form method="POST" action="?/addChecklistItem" use:enhance={() => {
return async ({ update, result }) => {
await update();
if (result.type === 'success') {
const form = document.querySelector(`form[data-checklist="${checklist.id}"]`) as HTMLFormElement;
if (form) resetInput(form);
}
};
}}
data-checklist={checklist.id}
class="mt-2 flex gap-2">
<input type="hidden" name="checklistId" value={checklist.id} />
<input type="text" name="text" required bind:value={newItemText[checklist.id]}
<input type="text" name="text" required
placeholder="Add item..."
class="flex-1 rounded-md border border-gray-200 px-2 py-1 text-sm focus:border-blue-500 focus:ring-1 focus:ring-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400" />
<button type="submit" class="rounded-md px-2 py-1 text-sm text-blue-600 hover:bg-blue-50 dark:text-blue-400 dark:hover:bg-blue-900/20">