Git Product home page Git Product logo

nuxt-validate's Introduction

Deprecated ⚠️

Use Vee-validate's official module instead

Nuxt Validate

Downloads Version License

Nuxt.js module for validations using Vee-Validate

Install

npm i --save nuxt-validate

Usage

Add module to nuxt.config.js

module.exports = {
  modules: [
    ...
    ['nuxt-validate', {
      lang: 'es',
      nuxti18n: {
        locale: {
          'zh-CN': 'zh_CN'
        }
      }
      ...
      // regular vee-validate options
      // https://github.com/logaretm/vee-validate/blob/master/docs/configuration.md
    }]
  ]
}

Using top level options

module.exports = {
  modules: [
    'nuxt-validate'
  ],
  nuxtValidate: {
    lang: 'es',
    nuxti18n: {
      locale: {
        'zh-CN': 'zh_CN'
      }
    }
  }
}

Configuration

lang

  • Default: undefined

The lang option accepts the name file placed on the locale dir of Vee-Validate repository without the extension.

rules

  • Default: undefined

If undefined, importing all rules. When listed from validation-rules, importing it.

nuxti18n: {
  rules: ['alpha_dash', 'min']
}

nuxti18n

  • Default: undefined

When nuxti18n option is set as a true, Vee-Validate's locale changes with nuxt-i18n's locale.
If nuxt-i18n's locale and Vee-Validate's locale are different, set locale object to convert locale code.

nuxti18n: {
  locale: {
    // nuxt-i18n's locale: Vee-Validate's locale
    'zh-cn': 'zh_CN',
    'zh-tw': 'zh_TW'
  }
}

⚠️ notice: If you use nuxt-i18n module, declare the nuxt-validate module at before it.

Documentation

Read the official Vee-Validate documentation and demos.

FAQ

How to add custom validation methods?

We recommend using plugins.

nuxt.config.js

module.exports = {
  plugins: ["~plugins/validate.js"],
}

plugins/validate.js

import { extend } from "vee-validate";

extend("my-validation", {
  message: "This {_field_} is invalid.",
  validate: value => {
    // ...
    return true;
  }
});

nuxt-validate's People

Contributors

aaharu avatar damisparks avatar edwinhoksberg avatar lewyuburi avatar ricardogobbosouza avatar seybsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nuxt-validate's Issues

Problems changing the languaage

Hi,

how can I change the language of nuxt-validate?
I also use nuxt-i18n.

In the readme there is the following line:

notice: If you use nuxt-i18n module, declare the nuxt-validate module at before it.
So my modules look like that at the moment.

  modules: [
    'bootstrap-vue/nuxt',
    '@nuxtjs/axios',
    '@nuxtjs/eslint-module',
    '@nuxtjs/sentry',
    'nuxt-validate',
    'nuxt-i18n'
  ],

So this is correct, right?

  1. How can I change the language statically to for example french.
  2. Why is nuxt-validate not picking the language from nuxt-i18n. What additional steps do I need?

Thank you!

NPM package is build wrongly

What happened?
"bundleDependencies": false,
"dependencies": {
"vee-validate": "^2.1.2"
},

Compare the vee-validate dependencie with the one of the repository.
In your repository it is 3.0.8 but if you install it via npm it is 2.1.2 (which has bugs)

Message from custom validators doesn't take effect

nuxt.config.js

module.exports = {
/// 
  /*
   ** Plugins to load beforve mounting the App
   */
  plugins: ["~plugins/validate.js"],
///
}

Alright, but how do you add a validation message?

/plugins/validate

	app.validator.extend('date', {
		validate: (value) => /^\d{2}([./-])\d{2}\1\d{2}$/.test(value),
		message: 'The {_field_} should be a valid date',
	});
};```

Still outputs the default error message: "The Start Date value is not valid"

How to add custom validation methods

I have 3 custom validators I need to add:

VeeValidate.Validator.extend('mobile', function (value) {
      var numbers = /^07[1-57-9]{1}[0-9]{8}$/
      var drama = /^07700900[0-9]{3}$/
      if (numbers.test(value) && !drama.test(value)) return true
      return false
    });
    VeeValidate.Validator.extend('dobAge', function (value, formData) {
      var data = formData
      var today = new Date()
      var birth = new Date(data['AppDOBYear'], parseInt(data['AppDOBMonth']) - 1, data['AppDOBDay'])
      var age = today.getFullYear() - birth.getFullYear()
      var month = today.getMonth() - birth.getMonth()
      if (month < 0 || month === 0 && today.getDate() < birth.getDate()) age--
      return age < 18 ? false : true
    });
    VeeValidate.Validator.extend('preventNumbers', function (value) {
      return value.match(/[0-9]/) ? false : true
    });

How can I add these?

handleSubmit is not a function (using ValidationObserver)

I've set up my form in a similar manner to this: https://logaretm.github.io/vee-validate/guide/forms.html#validate-before-submit

However when I use the ValidationObserver the invalid and handleSubmit slots don't seem to work? When I submit the form wrapped in the handleSubmit method I get handleSubmit is not a function. Also my button is not disabled by default with the invalid slot.

Everything else seems fine so I'm not sure if I'm missing something. Any help would be great, thanks!

Multi language

Hi, can we use multi language and set it in modules section?

export 'extend' was not found in 'vee-validate'

I created a file in plugins and added it to nuxt.config but I get export 'extend' was not found in 'vee-validate'

// ~/plugins/validate.js

import { extend } from 'vee-validate'

extend('postCode', (value) => {
  const reg = /^\d+$/
  if (value.length === 10 && reg.test(value)) {
    return true
  }
  return "{_field_}"
})

`Rules` property in nuxt.config.js is not respected

I have defined rules like so (two places, becasue I am unsure which -- not clear according to documentation):

	['nuxt-validate', {
		lang: 'en',
		rules: ['email', 'min', 'max', 'confirmed', 'numeric'],
		nuxti18n: {
			locale: {
				'da': 'da',
				'en': 'en'
			},
			rules: ['email', 'min', 'max', 'confirmed', 'numeric']
		},
		mode: 'eager',
		classes: {
			valid: 'is-success',
			invalid: 'is-danger'
		}
		// regular vee-validate options
		// https://github.com/logaretm/vee-validate/blob/master/docs/configuration.md
	}],

However, ALL rules are still being imported. For instance, I can use "digits" rule in my code without issues.

Configuration / options does not seem to take effect

I have tried customizing the options, like below:

	['nuxt-validate', {
		lang: 'en',
		rules: ['email', 'min', 'max', 'confirmed'],
		nuxti18n: {
			locale: {
				'da': 'da',
				'en': 'en'
			},
			rules: ['email', 'min', 'max', 'confirmed']
		},
		events: 'change',
		classes: {
			valid: 'is-success',
			invalid: 'is-danger'
		}
		// regular vee-validate options
		// https://github.com/logaretm/vee-validate/blob/master/docs/configuration.md
	}],

But classes / events are not being registered. What am I doing wrong?

Lazy loading

Hi,

I need vee-validate only on some specific pages. But vee-validate will be loaded on every page.
I want to reduce the size of my entry point by load vee-validate lazy only on components which really need this library.

How can I do this?

Thank you

Cross field validation not working

Trying to use cross-field validation to validate a password and password confirmation field but it's not working, the target/ref to refer doesn't actually return its value.

On the template I have:

<validation-observer ref="observer" v-slot="{invalid}" class="validation-observer" @submit.prevent="validate">
  <form class="standard-form">
    <div class="form-row">
      <div class="form-item">
        <h-text-field v-model="form.password" type="password" name="password" label="Password:" placeholder="Password" />
      </div>
    </div>
    <div class="form-row">
      <div class="form-item">
        <h-text-field v-model="form.password_confirmation" type="password" name="password_confirmation" label="Password Confirmation:" placeholder="Password Confirmation" />
      </div>
    </div>
    <button class="modern-cta-btn">
      Submit
    </button>
  </form>
</validation-observer>

the <h-text-field/> component simply renders a <ValidationProvider> with the rules for the fields and the name provided as prop.

And the rules are:

	password: 'required|password:password_confirmation',
	password_confirmation: 'required',

As per https://logaretm.github.io/vee-validate/advanced/cross-field-validation.html#targeting-other-fields I reference the password_confirmation (the name of the ValidationProvider) as an argument to that validation rule.

The validation rule:

/plugins/vee-validate.js

export default ({app}) => {
	app.validator.extend('password', {
                 params: ['target'],
		validate(value, [target]) {
			console.log('e: ', target);
			return true;
		},
		getMessage: () => 'Password confirmation does not match',
	});
}

The target always logs the name of the param password_confirmation instead of the actual value of that field

image

An overview of the setup

image

The last two fields are the password and the password confirmation

Unknown custom element: <ValidationProvider>

Does installing nuxt-validate requires to import ValidationProvider components or am I doing something wrong?

Here is my nuxt.config.js

modules: [ 'nuxt-validate'],
nuxtValidate: {
lang: 'en',
},

Add custom validation methods error ?

Hi.

I'm trying to create a custom rule for a password confirmation without success if someone can help me ?

I have inserted in my nuxt.config.js

  plugins: ['~plugins/vee-password.js'],

In plugins/vee-password.js

import { extend } from 'vee-validate'

extend('password', {
  params: ['target'],
  validate (value, { target }) {
    return value === target
  },
  message: 'Password confirmation does not match'
})

And when I start my app I have this error :

Capture d’écran 2019-11-25 à 15 27 42

Doc that I have found for this : https://github.com/lewyuburi/nuxt-validate#faq
Thx a lot ;p

Vee-Validate config

How do I access the vee-validate config object ?
I tried from the modules:
modules:[ ['nuxt-validate',{ fieldsBagName: 'vFields' } ]

but that doesnt work

Language option not described

Hello.
Thank you for a wonderful plugin.

I introduced a plugin and saw it.
However, the language option is not reflected.

I moved "Validator.localize" of plugin.js to the last line, the language was reflected.

Please consider examining the correction.

I am sorry for my poor English.

Multi language issue

Related to #4, maybe I'm doing something wrong because I get this error:

  Error: Could not compile template
  /home/paolo/devel/projects/bvk/node_modules/nuxt-validate/plugin.js:
  validatorLocale is not defined

nuxt.conf.js:

    ['nuxt-validate', {
      lang: 'it',
      nuxti18n: true
    }],
    ['nuxt-i18n', {
      lazy: true,
      langDir: 'i18n/',
      strategy: 'prefix_except_default',
      defaultLocale: 'it',
      locales: [
        {
          code: 'it',
          iso: 'it',
          name: 'IT',
          file: 'it.js',
        },
        {
          code: 'en',
          iso: 'en',
          name: 'EN',
          file: 'en.js',
        }
      ]
    }]
  ],

Any help?

Access to validation components

Does this module provide easy access to validation components (ValidationObserver, ValidationProvider and their instances)? I don't think so, at least I was unable to import them successfully from nuxt-validate therefore I ended up using vee-validate "manually" as my custom plugin, so I can do this now:

import { Component, Vue } from 'vue-property-decorator'
import { ValidationObserver, ValidationObserverInstance, ValidationProvider } from 'vee-validate'

@Component({
  components: {
    ValidationObserver,
    ValidationProvider,
  },
})
export default class Login extends Vue {
  $refs: {
    form: ValidationObserverInstance;
  }
  ...
}

Am I missing something? If not, would it be possible to make this available through nuxt-validate as well?

Use nuxt-i18n file

I have a nuxt project with nuxt-validate and nuxt-i18n.
Nuxt-i18n is configured to use a separate .json file with a custom langDir. When I try to use nuxt-validate, the locale switches correctly but the messages are not used from my translation file. I have used the standard root node "validations" and hoped it would be a plug and play solution but it's not..

['nuxt-validate', {
      rules: ['required'],
      nuxti18n: true
}],
['nuxt-i18n', {
      locales: [
        {
          name: 'Nederlands',
          code: 'nl',
          iso: 'nl-NL',
          file: 'nl.json'
        }
      ],
      langDir: 'i18n/',
      defaultLocale: 'nl',
      lazy: true,
      strategy: 'prefix_except_default'
    }],

I have also tried the vee-validate 3 fork from mole-inc but to no avail.

Any help would be much appreciated.

Integration with nuxt-i18n

Hey,

I'm curious if it'd be possible to integrate localization together with nuxt-i18n. Vee-validate already works together with vue-i18n (see here), so I guess it's possible 🤔

error at the project rebuilding

If I make some changes in nuxt.config.js when the dev-server is running, the dev-server rebuilds the project automatically and I get the error:

ERROR MomentLocalesPlugin: Moment.js doesn’t include a locale you specified: ru. Check the plugin’s localesToKeep option. 14:07:13
You can see the full list of locales that Moment.js includes in node_modules/moment/locale/
You can see the full list of locales that Moment.js includes in node_modules/moment/locale/
at normalizeLocalesToKeep (node_modules/moment-locales-webpack-plugin/index.js:67:15)
at checkOptions (node_modules/moment-locales-webpack-plugin/index.js:31:25)
at new MomentLocalesPlugin (node_modules/moment-locales-webpack-plugin/index.js:87:29)
at WebpackBundler.extendBuild (node_modules/@nuxtjs/moment/lib/module.js:18:25)
at WebpackBundler. (node_modules/@nuxt/utils/dist/utils.js:1812:25)
at WebpackClientConfig.extendConfig (node_modules/@nuxt/webpack/dist/webpack.js:4766:37)
at WebpackClientConfig.config (node_modules/@nuxt/webpack/dist/webpack.js:4796:45)
at WebpackClientConfig.config (node_modules/@nuxt/webpack/dist/webpack.js:4965:26)
at WebpackBundler.getWebpackConfig (node_modules/@nuxt/webpack/dist/webpack.js:5267:19)
at WebpackBundler.build (node_modules/@nuxt/webpack/dist/webpack.js:5274:12)
at Builder.build (node_modules/@nuxt/builder/dist/builder.js:5578:30)

If I stop the dev-server and run it again (nuxt build) the error does not appear.

My config:
['nuxt-validate', {lang: 'ru'}],

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.