All skills
skilld-dev avatar

/tanstack-vue-form-skilld

@b9c39cb

Use when writing, reviewing, or debugging code that imports @tanstack/vue-form (TanStack Form for Vue). Covers the 1.33.x API, including useForm, form.Field, form.FormGroup, form.Subscribe, form.useSelector, validators with Standard Schema, onDynamic with revalidateLogic, and array fields with mode="array". Result, forms built on current, non-deprecated Vue APIs with correct reactivity.

Use this Skill: https://skilld.dev/gh/skilld-dev/vue-ecosystem-skills/tanstack-vue-form-skilld

This session only. Nothing lands on disk.

referencesarray-fields.md

≈725 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Array fields in @tanstack/vue-form

Official guide: https://tanstack.com/form/latest/docs/framework/vue/guides/arrays

Use mode="array"

Give the wrapping field the mode="array" prop. The option exists on field options as mode?: 'value' | 'array' (src/types.ts:12-15, prepared source).

Why it exists: in array mode useField tracks state.meta._arrayVersion instead of the value identity, so edits to one row do not re-render every row (src/useField.tsx:258-267). The value is then read straight from fieldApi.state.value (src/useField.tsx:310-311). Background: https://github.com/TanStack/form/issues/1925

Shape

<script setup lang="ts">
import { useForm } from '@tanstack/vue-form'

const form = useForm({
  defaultValues: {
    people: [] as Array<{ age: number; name: string }>,
  },
  onSubmit: ({ value }) => console.log(value),
})
</script>

<template>
  <form @submit.prevent.stop="form.handleSubmit">
    <form.Field name="people" mode="array">
      <template v-slot="{ field }">
        <div>
          <form.Field
            v-for="(_, i) of field.state.value"
            :key="i"
            :name="`people[${i}].name`"
          >
            <template v-slot="{ field: subField }">
              <input
                :value="subField.state.value"
                @input="(e) => subField.handleChange((e.target as HTMLInputElement).value)"
              />
            </template>
          </form.Field>
          <button type="button" @click="field.pushValue({ name: '', age: 0 })">
            Add person
          </button>
        </div>
      </template>
    </form.Field>
    <button type="submit">Submit</button>
  </form>
</template>

Sub-field names are deep keys with the index inline: `people[${i}].name`. Keys can go arbitrarily deep into objects inside arrays.

Mutation methods

On a field (FieldApi):

  • pushValue(value)
  • removeValue(index)
  • insertValue(index, value)
  • replaceValue(index, value)
  • moveValue(aIndex, bIndex)
  • swapValues(aIndex, bIndex)
  • clearValues()

On the form (FormApi), the same operations addressed by field name:

  • pushFieldValue(name, value)
  • removeFieldValue(name, index)
  • insertFieldValue(name, index, value)
  • replaceFieldValue(name, index, value)
  • moveFieldValues(name, aIndex, bIndex)
  • swapFieldValues(name, aIndex, bIndex)
  • clearFieldValues(name)

The form also exposes validateArrayFieldsStartingFrom(name, startIndex) and validateAllFields() for targeted revalidation after array edits.

Notes

  • Render the empty state from the array field itself: Array.isArray(field.state.value) && !field.state.value.length.
  • Use v-for over field.state.value of the array field; do not copy the array into local state.
  • Remove buttons inside rows should call the parent array field's removeValue(i) with type="button" so they do not submit the form.

Source: SKILL.md on GitHub

No alerts8d3 checks · Risk SAFE
  • Gen Agent Trust Hub8d

    This skill serves as a comprehensive knowledge base and reference guide for the @tanstack/vue-form library. It includes API documentation, best practices, common issues, and community discussions. No malicious behavior, security vulnerabilities, or suspicious code patterns were detected.

  • Socket8d

    No alerts

  • Snyk8d

    Risk: LOW · No issues

Signed by skilld at b9c39cb. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated last week

README badge

README badge for skilld-dev/vue-ecosystem-skills/tanstack-vue-form-skilld