Loading...
Loading...
ALWAYS use when writing code importing "@tanstack/vue-form". Consult for debugging, best practices, or modifying @tanstack/vue-form, tanstack/vue-form, tanstack vue-form, tanstack vue form, form.
npx skill4agent add harlan-zw/vue-ecosystem-skills tanstack-vue-form-skilld@tanstack/vue-form@tanstack/vue-formfield.errors[error][[error]]disableErrorFlat: truefield.getValue()field.state.valuefield.parseValueWithSchema()form.parseValuesWithSchema()formOptions()useFormFielduseFieldSubscribeuseStore()resetField()FormApiclearFieldValues()FormApisetErrorMap()StandardSchemaV1modeUseFieldOptions'value''array'disableErrorFlatFieldApiOptionsresetFieldMeta()insertFieldValue()moveFieldValues()swapFieldValues()FieldApi.getInfo()VueFieldApiVueFormApiformOptions()const options = formOptions({
defaultValues: { email: '' },
validators: {
onChange: z.object({ email: z.string().email() })
}
})
const form = useForm(options)onChangeListenTo<form.Field
name="confirm_password"
:validators="{
onChangeListenTo: ['password'],
onChange: ({ value, fieldApi }) =>
value !== fieldApi.form.getFieldValue('password') ? 'Passwords do not match' : undefined
}"
>async-debounce-ms<form.Field
name="username"
:async-debounce-ms="500"
:validators="{
onChangeAsync: async ({ value }) => checkUsername(value)
}"
>onSubmitconst form = useForm({
onSubmit: ({ value }) => {
// schema.parse converts string to number if transform is defined
const validatedData = loginSchema.parse(value)
api.submit(validatedData)
}
})onSubmitMetaonSubmit<button @click="form.handleSubmit({ action: 'save_draft' })">Save Draft</button>
<button @click="form.handleSubmit({ action: 'publish' })">Publish</button>canSubmitisPristine<template v-slot="{ canSubmit, isPristine }">
<button :disabled="!canSubmit || isPristine">Submit</button>
</template>form.useStore<script setup>const canSubmit = form.useStore((state) => state.canSubmit)asyncAlways: true// Runs async validation even if local regex check fails
const validators = {
onChange: ({ value }) => !value.includes('@') ? 'Invalid' : undefined,
onChangeAsync: async ({ value }) => api.check(value),
asyncAlways: true
}fieldsvalidators: {
onChange: ({ value }) => ({
fields: {
startDate: value.startDate > value.endDate ? 'Must be before end' : undefined,
endDate: value.startDate > value.endDate ? 'Must be after start' : undefined
}
})
}defaultValuesconst { data } = useQuery(...)
const defaultValues = reactive({
name: computed(() => data.value?.name ?? '')
})
const form = useForm({ defaultValues })