Skip to content

Commit 0d719a1

Browse files
committed
refactor(form): use snippet for form children
Refactor Form usage to wrap children in a snippet block, enabling access to isDirty, errors, and hasErrors via the snippet context instead of let directives. This aligns with updated Svelte syntax and improves code clarity.
1 parent adb6a9b commit 0d719a1

File tree

1 file changed

+20
-18
lines changed
  • packages/svelte5/test-app/Pages/FormComponent

1 file changed

+20
-18
lines changed

packages/svelte5/test-app/Pages/FormComponent/Ref.svelte

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,29 @@
3333
<div>
3434
<h1>Form Ref Test</h1>
3535

36-
<Form bind:this={formRef} action="/dump/post" method="post" let:isDirty let:errors let:hasErrors>
37-
<!-- State display for testing -->
38-
<div>Form is {isDirty ? 'dirty' : 'clean'}</div>
39-
{#if hasErrors}
40-
<div>Form has errors</div>
41-
{/if}
42-
{#if errors.name}
43-
<div id="error_name">{errors.name}</div>
44-
{/if}
36+
<Form bind:this={formRef} action="/dump/post" method="post">
37+
{#snippet children({ isDirty, errors, hasErrors })}
38+
<!-- State display for testing -->
39+
<div>Form is {isDirty ? 'dirty' : 'clean'}</div>
40+
{#if hasErrors}
41+
<div>Form has errors</div>
42+
{/if}
43+
{#if errors.name}
44+
<div id="error_name">{errors.name}</div>
45+
{/if}
4546

46-
<div>
47-
<input type="text" name="name" placeholder="Name" value="John Doe" />
48-
</div>
47+
<div>
48+
<input type="text" name="name" placeholder="Name" value="John Doe" />
49+
</div>
4950

50-
<div>
51-
<input type="email" name="email" placeholder="Email" value="[email protected]" />
52-
</div>
51+
<div>
52+
<input type="email" name="email" placeholder="Email" value="[email protected]" />
53+
</div>
5354

54-
<div>
55-
<button type="submit">Submit via Form</button>
56-
</div>
55+
<div>
56+
<button type="submit">Submit via Form</button>
57+
</div>
58+
{/snippet}
5759
</Form>
5860

5961
<div>

0 commit comments

Comments
 (0)