0.7.7 • Published 2 years ago

vuelidate v0.7.7

Weekly downloads
208,554
License
MIT
Repository
github
Last release
2 years ago

vuelidate

codecov gzip size

Simple, lightweight model-based validation for Vue.js

Sponsors

Gold

Silver

Bronze

Features & characteristics:

  • Model based
  • Decoupled from templates
  • Dependency free, minimalistic library
  • Support for collection validations
  • Support for nested models
  • Contextified validators
  • Easy to use with custom validators (e.g. Moment.js)
  • Support for function composition
  • Validates different data sources: Vuex getters, computed values, etc.

Demo & docs

https://vuelidate.js.org/

Vue 3 support

Vue 3 support is almost here with the Vuelidate 2 rewrite. Check out the next branch to see the latest progress.

Installation

npm install vuelidate --save

You can import the library and use as a Vue plugin to enable the functionality globally on all components containing validation configuration.

import Vue from 'vue'
import Vuelidate from 'vuelidate'
Vue.use(Vuelidate)

Alternatively it is possible to import a mixin directly to components in which it will be used.

import { validationMixin } from 'vuelidate'

var Component = Vue.extend({
  mixins: [validationMixin],
  validations: { ... }
})

The browser-ready bundle is also provided in the package.

<script src="vuelidate/dist/vuelidate.min.js"></script>
<!-- The builtin validators is added by adding the following line. -->
<script src="vuelidate/dist/validators.min.js"></script>
Vue.use(window.vuelidate.default)

Basic usage

For each value you want to validate, you have to create a key inside validations options. You can specify when input becomes dirty by using appropriate event on your input box.

import { required, minLength, between } from 'vuelidate/lib/validators'

export default {
  data () {
    return {
      name: '',
      age: 0
    }
  },
  validations: {
    name: {
      required,
      minLength: minLength(4)
    },
    age: {
      between: between(20, 30)
    }
  }
}

This will result in a validation object:

$v: {
  name: {
    "required": false,
    "minLength": false,
    "$invalid": true,
    "$dirty": false,
    "$error": false,
    "$pending": false
  },
  age: {
    "between": false
    "$invalid": true,
    "$dirty": false,
    "$error": false,
    "$pending": false
  }
}

Checkout the docs for more examples: https://vuelidate.js.org/

Contributing

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# create UMD bundle.
npm run build

# Create docs inside /gh-pages ready to be published
npm run docs

# run unit tests
npm run unit

# run all tests
npm test

For detailed explanation on how things work, checkout the guide and docs for vue-loader.

Contributors

Current

Emeriti

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

License

MIT

vue-nxp-pluginsb-filmothequeresource-hubnr-componentsui-kit-oohdesk@ixlayer/ixlayer-componentsquasar-app-extension-stellar-formsauth-oside@monukanyal/multiple-tagemail-componenthungtv12345store-componentsvue-components-laurensbuildinglinkvue-dynamic-gridnotary-fees-calcnotaryfeescalcnotary-fees-cal@filipigustavo/workplace-registrationsalesforce-query-editor@selfagencyllc/dev-tools-vuequasar-app-extension-imagina-extinfonaligy-vue-components@infonaligy/inf-vue-componentsrb-ui-quasarsalesforce-query-editor-app@onereach/step-inputs-commonquasar-app-extension-stellarquasar-app-extension-vuelidate-rules-v2@onereach/lib-assistsalesforce-query-editor-test@prefix/studio-editorteranos-001005-ui-kitraida_form@eipgrid/s1@infinitebrahmanuniverse/nolb-vuelswsc-esigna-mobilelightswitch-storefront@everything-registry/sub-chunk-3102publish-dataset-frontend-testshopexpress-coresimple-form-managershark-commonsshop-appdx-uiegg-born-showcase-watch-articlesengagivdemo-hr-portalsala-components-v2rocktime-webpacksavtestsafabasesbc-common-componentsrenderformsspn-utilityelementlysongtracker-proehldev-admin-librarysone-nuxt-module-vuelidatesone-frontend-componentssmart-faq-feeipgrid-maineipgrid-widget1quasar-ui-pablo-prueba-quasarquasar-ui-histrix-clientcs-componentsquasar-app-extension-govbrdmf_auth_vuesitewhere-ide-componentssitewhere-admin-ui-plugins@avto-dev/bank-card-vue-componentosmanli-veri-dagitimosmanli-yatirim@ayg/hm-plugincafe-ui-extendclformcontrols@carrene/chatboxcnn-content-hubcloud-template-testcloud-test-onecolorwallet@chargetrip/internal-vue-components@cling-se/widget@cnmc/miscomponentesvuecoreform-components@craydel/craydel-file-input@craydel/craydel-password-field@craydel/craydel-phone-field@craydel/craydel-radio-group@craydel/craydel-select@craydel/craydel-text-field@craydel/craydel-textarea@craydel/craydel-autocomplete@craydel/craydel-date-picker@coreform/components@coscine/project-creation@croudtech/vue-connect-uipdf-report-generatorpharmasoft-core-vue
0.7.7

2 years ago

0.7.6

3 years ago

0.7.5

4 years ago

0.7.4

6 years ago

0.7.3

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.2

6 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago