Vee-Validate

Painless Vue forms

README

Painless Vue forms

Features

- 🍞 Easy: Declarative validation that is familiar and easy to setup
- 🧘‍♀️ Flexible: Synchronous, Asynchronous, field-level or form-level validation
- ⚡️ Fast: Build faster forms faster with intuitive API and small footprint
- 🏏 Minimal: Only handles the complicated form concerns, gives you full control over everything else
- 😎 UI Agnostic: Works with native HTML elements or your favorite UI library components
- 🦾 Progressive: Works whether you use Vue.js as a progressive enhancement or in a complex setup
- ✅ Built-in Rules: Companion lib with 25+ Rules that covers most needs in most web applications
- 🌐 i18n: 45+ locales for built-in rules contributed by developers from all over the world

Getting Started

Installation

  1. ```sh
  2. # Install with yarn
  3. yarn add vee-validate
  4. # Install with npm
  5. npm install vee-validate --save
  6. ```

Vue version support

The main v4 version supports Vue 3.x only, for previous versions of Vue, check the following the table
vuevee-validateDocumentation
-----------------------------------------------------------------------------------------------------------------------
`2.x``2.x`[v2](https://vee-validate.logaretm.com/v2)
`3.x``4.x`[v4](https://vee-validate.logaretm.com/v4)

Usage

vee-validate offers two styles to integrate form validation into your Vue.js apps.

Declarative Components

Higher-order components are better suited for most of your cases. Register the Field and Form components and create a simple required validator:
  1. ``` js
  2. import { Field, Form } from 'vee-validate';
  3. export default {
  4.   components: {
  5.     Field,
  6.     Form,
  7.   },
  8.   methods: {
  9.     isRequired(value) {
  10.       return value ? true : 'This field is required';
  11.     },
  12.   },
  13. };
  14. ```
Then use the Form and Field components to render your form:
  1. ```vue
  2. <Form v-slot="{ errors }">
  3.   <Field name="field" :rules="isRequired" />
  4. <span>{{ errors.field }}</span>
  5. </Form>
  6. ```
The Field component renders an input of type text by default but you can control that

Composition API

If you want more fine grained control, you can use useField function to compose validation logic into your component:
  1. ``` js
  2. import { useField } from 'vee-validate';
  3. export default {
  4.   setup() {
  5.     // Validator function
  6.     const isRequired = value => (value ? true : 'This field is required');
  7.     const { value, errorMessage } = useField('field', isRequired);
  8.     return {
  9.       value,
  10.       errorMessage,
  11.     };
  12.   },
  13. };
  14. ```
Then in your template, use v-model to bind the value to your input and display the errors using errorMessage:
  1. ```vue
  2. <input name="field" v-model="value" />
  3. <span>{{ errorMessage }}</span>
  4. ```

📚 Documentation

Contributing

You are welcome to contribute to this project, but before you do, please make sure you read the contribution guide.

Credits

- Inspired by Laravel's validation syntax
- v4 API Inspired by Formik's
- Logo by Baianat

Emeriti

Here we honor past contributors and sponsors who have been a major part on this project.

⚖️ License

Released under MIT by @logaretm.