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

App.vue

39 lines938 Bytes

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