Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

App.svelte

37 lines832 Bytes

1<script lang="ts">
2 import ArrayForm from './ArrayForm.svelte'
3 import './index.css'
4​
5 let itemAmount = $state(50)
6 let requestedAmount = $state(50)
7 let items = $derived(Array.from({ length: itemAmount }, () => ''))
8​
9 function updateItems() {
10 if (!Number.isNaN(requestedAmount)) {
11 itemAmount = Math.min(10_000, Math.max(0, requestedAmount))
12 }
13 }
14</script>
15​
16<div>
17 <h1>Arrays in Form Example</h1>
18 <label for="itemsAmount">
19 Enter the amount of items to render with the form.
20 <br />
21 Note that it will reset the state.
22 </label>
23 <br />
24 <input
25 id="itemsAmount"
26 type="number"
27 bind:value={requestedAmount}
28 min="1"
29 step="1"
30 max="10000"
31 />
32 <button type="button" onclick={updateItems}>Update</button>
33 <br />
34 {#key itemAmount}
35 <ArrayForm {items} />
36 {/key}
37</div>