UNPKG

5.45 kBMarkdownView Raw
1<p align="center">
2 <a href="https://vee-validate.logaretm.com" target="_blank">
3 <img src="https://raw.githubusercontent.com/logaretm/vee-validate/main/logo.png" width="200" title="Go to website">
4 </a>
5</p>
6
7<p align="center">
8Painless Vue forms
9</p>
10
11<p align="center">
12
13<a target="_blank" href="https://www.npmjs.com/package/vee-validate">
14 <img src="https://img.shields.io/npm/v/vee-validate.svg?label=&color=05bda8">
15</a>
16
17<a target="_blank" href="https://npm-stat.com/charts.html?package=vee-validate">
18 <img src="https://img.shields.io/npm/dm/vee-validate.svg?color=05bd6d&label=">
19</a>
20
21<a href="https://vee-validate.logaretm.com/v4/" target="_blank">
22 <img src="https://img.shields.io/badge/-docs%20and%20demos-009f53">
23</a>
24
25<a href="https://github.com/sponsors/logaretm">
26 <img src="https://img.shields.io/badge/-%E2%99%A5%20Sponsors-ec5cc6">
27
28</a>
29
30</p>
31
32<br>
33
34<p align="center">
35 <a href="https://github.com/sponsors/logaretm">
36 <img src='https://sponsors.logaretm.com/sponsors.svg'>
37 </a>
38</p>
39
40<br>
41
42## Features
43
44- **🍞 Easy:** Declarative validation that is familiar and easy to setup
45- **🧘‍♀️ Flexible:** Synchronous, Asynchronous, field-level or form-level validation
46- **⚡️ Fast:** Build faster forms faster with intuitive API and small footprint
47- **🏏 Minimal:** Only handles the complicated form concerns, gives you full control over everything else
48- **😎 UI Agnostic:** Works with native HTML elements or your favorite UI library components
49- **🦾 Progressive:** Works whether you use Vue.js as a progressive enhancement or in a complex setup
50- **✅ Built-in Rules:** Companion lib with 25+ Rules that covers most needs in most web applications
51- **🌐 i18n:** 45+ locales for built-in rules contributed by developers from all over the world
52
53## Getting Started
54
55### Installation
56
57```sh
58# Install with yarn
59yarn add vee-validate
60
61# Install with npm
62npm install vee-validate --save
63```
64
65### Vue version support
66
67The main v4 version supports Vue 3.x only, for previous versions of Vue, check the following the table
68
69| vue Version | vee-validate version | Documentation Link |
70| ----------- | -------------------- | ---------------------------------------------------------------------------------------- |
71| `2.x` | `2.x` or `3.x` | [v2](https://vee-validate.logaretm.com/v2) or [v3](https://vee-validate.logaretm.com/v3) |
72| `3.x` | `4.x` | [v4](https://vee-validate.logaretm.com/v4) |
73
74### Usage
75
76vee-validate offers two styles to integrate form validation into your Vue.js apps.
77
78#### Composition API
79
80The fastest way to create a form and manage its validation, behavior, and values is with the composition API.
81
82Create your form with `useForm` and then use `defineField` to create your field model and props/attributes and `handleSubmit` to use the values and send them to an API.
83
84```vue
85<script setup>
86import { useForm } from 'vee-validate';
87
88// Validation, or use `yup` or `zod`
89function required(value) {
90 return value ? true : 'This field is required';
91}
92
93// Create the form
94const { defineField, handleSubmit, errors } = useForm({
95 validationSchema: {
96 field: required,
97 },
98});
99
100// Define fields
101const [field, fieldProps] = defineField('field');
102
103// Submit handler
104const onSubmit = handleSubmit(values => {
105 // Submit to API
106 console.log(values);
107});
108</script>
109
110<template>
111 <form @submit="onSubmit">
112 <input v-model="field" v-bind="fieldProps" />
113 <span>{{ errors.field }}</span>
114
115 <button>Submit</button>
116 </form>
117</template>
118```
119
120You can do so much more than this, for more info [check the composition API documentation](https://vee-validate.logaretm.com/v4/guide/composition-api/getting-started/).
121
122#### Declarative Components
123
124Higher-order components can also be used to build forms. Register the `Field` and `Form` components and create a simple `required` validator:
125
126```vue
127<script setup>
128import { Field, Form } from 'vee-validate';
129
130// Validation, or use `yup` or `zod`
131function required(value) {
132 return value ? true : 'This field is required';
133}
134
135// Submit handler
136function onSubmit(values) {
137 // Submit to API
138 console.log(values);
139}
140</script>
141
142<template>
143 <Form v-slot="{ errors }" @submit="onSubmit">
144 <Field name="field" :rules="required" />
145
146 <span>{{ errors.field }}</span>
147
148 <button>Submit</button>
149 </Form>
150</template>
151```
152
153The `Field` component renders an `input` of type `text` by default but you can [control that](https://vee-validate.logaretm.com/v4/api/field#rendering-fields)
154
155## 📚 Documentation
156
157Read the [documentation and demos](https://vee-validate.logaretm.com/v4).
158
159## Contributing
160
161You are welcome to contribute to this project, but before you do, please make sure you read the [contribution guide](/CONTRIBUTING.md).
162
163## Credits
164
165- Inspired by Laravel's [validation syntax](https://laravel.com/docs/5.4/validation)
166- v4 API Inspired by [Formik's](https://github.com/formium/formik)
167- Nested path types by [react-hook-form](https://github.com/react-hook-form/react-hook-form)
168- Logo by [Baianat](https://github.com/baianat)
169
170## Emeriti
171
172Here we honor past contributors and sponsors who have been a major part on this project.
173
174- [Baianat](https://github.com/baianat).
175
176## ⚖️ License
177
178Released under [MIT](/LICENSE) by [@logaretm](https://github.com/logaretm).