Skip to content

Form

The <Form /> component functions like a native form but includes additional behind the scenes functionality. It helps collect form data, manage validations, and handle submissions.

Basic usage

vue
<script lang="ts" setup>
import { Form, Field } from 'vue-formify';

const sendForm = (data) => {
	console.log(data);
};

</script>
<template>
	<Form @submit="sendForm">
		<Field name="first_name" />
		<Field name="last_name" />
		<button>Send</button>
	</Form>
</template>

Api reference

Props

Prop nameDescription
enctypeSpecifies how the form data should be encoded.
initialValuesSets initial values for form elements.
validation-schemaAccepts a validation schema object from yup, zod, valibot, or joi.
preservePreserves form data even when the Form component is unmounted.
nameDefines the name of the form.

Events

EventDescription
submitSends form data, with data automatically extracted.
value-changeTriggers an event when form data changes, useful for side effects.

Methods

MethodParameterDescription
resetvoidReset form.
flushvoidForced reset.
setError{ name: string; error: any }Set error messages for specified input.

Exposed variables

NameDescription
isSubmittingForm submitting state
valuesForm field values
errorsForm field errors

Slots

SlotParameterDescription
default{ values, errors }Gives back the form data and errors.