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@craydel-v3/craydel-select@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@craterapp/vue-sdk@creatiwity/formbuilder@perezguedesmaikel/chile-atiende-uijarch-vuejarvis-componentskafka-uikitaokitao-componentsserega-nuxt-3songtracker-prosp-quasar-authvue-perfect-auth@apatheticwes/validation@arissian/luciditi-sign-in-sdk@cciiccee/test-test@chronicstone/vue-sweetforms@chronicstone/vue-sweettools@choosemycompany/cmc-components@1doc3/hermes-chat@23zane/vue-validator@actindo/core-ui@actindo/datahub@datam/design-system@dargmuesli/nuxt-viovuefrontvuefront-moonomen-themevuelidate-validators-javue-sdzvue-ui-kit-basicvillevi-form-builder@harv46/valid-input@garage44/pyrite@infinitebrahmanuniverse/nolb-_vuel@konnec/vue-eloquent@liquiddesign/vue-forms@leaflink/leaflink-ui@lbtek/form-inputs-vue@itron/makeover@energysage/es-ds-components@e7a/everright-filter@marwan-elabhar/my-nuxt-layer@jibeh/fastmiam-rgpd@justserdar/tunga@ppjmorales/creator_template@rwapp/quasar-app-extension-vue-core-v2@notoursllc/figleaf@ocph23/vtocph23mlrdev-vue3-librarynawadashowse-search-framework-vue-3pangea-libnq-ccp-ui-kitpdap-design-systemquasar-app-extension-quasar-validate-rulesquasar-app-extension-villequasar-app-extension-vuelidate-rulessevenlab-boilerplate-appnboard-ui-ratanboard-ui-rednextline-webplxnnerquery-filter-runsa
2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 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

3 years ago

2.0.0-alpha.27

3 years ago

2.0.0-alpha.26

3 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

4 years ago

2.0.0-alpha.12

4 years ago

2.0.0-alpha.11

4 years ago

2.0.0-alpha.10

4 years ago

2.0.0-alpha.9

4 years ago

2.0.0-alpha.8

4 years ago

2.0.0-alpha.7

4 years ago

2.0.0-alpha.6

4 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