Skip to content

Getting Started

Installation

sh
$ npm install @vuetils/form
sh
$ pnpm add @vuetils/form@latest
sh
$ yarn add @vuetils/form

Usage

You start of by creating a Form instance with useForm(). The function takes in an object where every property represents an input element in your form. The key of the property corresponds to the name attribute of an input element and the value is an array where the first element is the initial value of the input and the second element is an array of validators.

vue
<script setup>
import { UForm, UInput, email, minLength, required, useForm } from '@vuetils/form';

const form = useForm({
	email: ['', [required, email]],
	password: ['', [required, minLength(6)]],
});
</script>

@vuetils/form provides two helper componets that automatically link a Form instance with your input elements. The components handle two-way data binding and add validation classes like v-valid or v-submitted.

vue
<template>
	<UForm :form="form">
		<label>
			Email:
			<UInput type="email" name="email" />
		</label>

		<label>
			Password:
			<UInput type="password" name="password" />
		</label>

		<button>Submit</button>
	</UForm>
</template>

The rendered form will look something like this. Play around with it and see how the errors and state change while you are typing.

What's Next?

Released under the MIT License.