2.0.4 • Published 2 years ago

@vuelidate/validators v2.0.4

Weekly downloads
3,243
License
MIT
Repository
github
Last release
2 years ago

Vuelidate Validators

This is the standalone validators package for Vuelidate.

Installation

You need to install both this package and Vuelidate.

npm install @vuelidate/core @vuelidate/validators

or with yarn

yarn add @vuelidate/core @vuelidate/validators

Usage

After adding the Vuelidate plugin, you can use the validators by importing them directly. These validators come with error messages out of the box.

import { required, email } from '@vuelidate/validators'

export default {
  data: () => ({
    name: '',
    email: ''
  }),
  validations: {
    name: { required },
    email: { required, email }
  }
}

Raw, no message validators

If you want to use validators without error messages, you can import the raw validators.

import { required, email } from '@vuelidate/validators/dist/raw.esm'

Extending a validator with custom message

You can attach a validation message to a validator via tha withMessage method.

import { common, required } from '@vuelidate/validators'

const requiredWithMessage = common.withMessage(required, 'This field is required and must be filled in')

export default {
  ...,
  validations: {
    name: { requiredWithMessage }
  }
}

Attaching extra data to a validator

If you want to attach extra data properties to validator, so you can use them in the messages and when validating, use the withParams helper.

import { common } from '@vuelidate/validators'

const atLeast = (number) => common.withParams({ number }, (value) => value.length <= number) // just an example

export default {
  ...,
  validations: {
    name: { atLeast: atLeast(5) }
  }
}

Combining params and messages

You can combine both helpers to build a validator.

import { common } from '@vuelidate/validators'

const customMinLength = (number) => common.withMessage((value) => value.length <= number, ({ $params }) => `The field must be at least ${$params.number} chars long`)
const atLeast = (number) => common.withParams({ number }, customMinLength(number)) // just an example

export default {
  ...,
  validations: {
    name: { atLeast: atLeast(5) }
  }
}

Development

To test the package run

yarn test:unit

To link the package run

yarn link

To build run the package, run:

npm run build
@hovrcat/translatorvue-isc-library@prefix/studio-editornboard-uicarbon-zerocarbon-zero-web-widgetcarbon-zero-widget_simonpersonal-zer0personal-zerotest-package-vue@everything-registry/sub-chunk-995mui-vue3@visitscotland/component-library-exporttaas-base-componentstest-mlr-libraryvvalidationwertyz-vuewertyz-vue-3wr-projectstory-kit-t2story-kit-t3starter-vuetest-ui-waaasushil-component-libsushil-viewer-vuevcs2-nuxt-module-2vue-experience-componentsvue-bootstrap-login@perezguedesmaikel/chile-atiende-uijarch-vuejarvis-componentskafka-uikitaokitao-componentshyshan-form-validationhgv-nuxt-core-temphapex-uigvt-checkout-modallits-vue-elementslinks-vue-frameworklzl-everright-formeditorkodama-ui@webitel/ui-sdk@wmfs/json-to-vuelidate@wntr/lx-ui@thzero/library_client_vue3@thzero/library_client_vue3_vuetify3@timcowebapps/vue-auth@timcowebapps/vue-uikit@tokene/sdk@tokene/toolkit@visitscotland/component-library@visitscotland/vs-component-library@vision-aura/vue-core@vivaconagua/vueca@zalastax/nolb-_vuel@zhycit/jyiai-auth-vue3@zdzcode/zc-web-vuejs-coreagrobank-coreadata-ui-v2azaas-process-designerapp-my-library@chronicstone/vue-sweetforms@chronicstone/vue-sweettools@choosemycompany/cmc-components@cling-se/widget@1doc3/hermes-chat@23zane/vue-validator@actindo/core-ui@actindo/datahub@actindo/globaldrivermanagement@actindo/setting@harv46/valid-input@e7a/everright-filter@craterapp/vue-sdk@craydel-v3/craydel-text-field@craydel-v3/craydel-textarea@craydel-v3/craydel-time-picker@craydel-v3/craydel-autocomplete@craydel-v3/craydel-date-picker@craydel-v3/craydel-date-range-picker@craydel-v3/craydel-file-input@craydel-v3/craydel-password-field@craydel-v3/craydel-select@creatiwity/formbuilder@connect-development/connect-uiserega-nuxt-3songtracker-prosp-quasar-authvue-perfect-auth@cciiccee/test-testvuefrontvuefront-moonomen-themevuelidate-validators-javue-sdzvue-ui-kit-basicvillevi-form-builder@garage44/pyrite@infinitebrahmanuniverse/nolb-_vuel
2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0-alpha.32

3 years ago

2.0.0

3 years ago

2.0.0-alpha.31

3 years ago

2.0.0-alpha.30

3 years ago

2.0.0-alpha.29

3 years ago

2.0.0-alpha.28

4 years ago

2.0.0-alpha.27

4 years ago

2.0.0-alpha.26

4 years ago

2.0.0-alpha.25

4 years ago

2.0.0-alpha.24

4 years ago

2.0.0-alpha.23

4 years ago

2.0.0-alpha.22

4 years ago

2.0.0-alpha.21

4 years ago

2.0.0-alpha.20

4 years ago

2.0.0-alpha.19

4 years ago

2.0.0-alpha.18

4 years ago

2.0.0-alpha.17

4 years ago

2.0.0-alpha.16

4 years ago

2.0.0-alpha.15

4 years ago

2.0.0-alpha.14

4 years ago

2.0.0-alpha.13

5 years ago

2.0.0-alpha.12

5 years ago

2.0.0-alpha.11

5 years ago

2.0.0-alpha.10

5 years ago

2.0.0-alpha.9

5 years ago

2.0.0-alpha.8

5 years ago

2.0.0-alpha.7

5 years ago

2.0.0-alpha.6

5 years ago

2.0.0-alpha.5

5 years ago

2.0.0-alpha.4

5 years ago

2.0.0-alpha.3

5 years ago

2.0.0-alpha.2

5 years ago

2.0.0-alpha.1

5 years ago

2.0.0-alpha.0

6 years ago

1.0.0-alpha.2

6 years ago