From 3ede9afd9d5a94f30421fc5fd1e36d3f6289bc20 Mon Sep 17 00:00:00 2001 From: Haruaki OTAKE Date: Mon, 7 Oct 2019 00:02:32 +0900 Subject: [PATCH] docs: update readme --- readme.md | 72 +++++++++++++++++++++++++++++++++++++++++---- templates/plugin.js | 1 - 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index aa3392c..4902e19 100644 --- a/readme.md +++ b/readme.md @@ -6,7 +6,7 @@ License

-Nuxt.js module for validations using [Vee-Validate](https://github.com/baianat/vee-validate) +Nuxt.js module for validations using [Vee-Validate](https://github.com/logaretm/vee-validate) ## Install @@ -31,25 +31,57 @@ module.exports = { } ... // regular vee-validate options + // https://github.com/logaretm/vee-validate/blob/master/docs/configuration.md }] ] } ``` +### Using top level options + +```js +module.exports = { + modules: [ + 'nuxt-validate' + ], + nuxtValidate: { + lang: 'es', + nuxti18n: { + locale: { + 'zh-CN': 'zh_CN' + } + } + } +} +``` + ### Configuration #### `lang` -- Default: `en` +- Default: `undefined` + +The `lang` option accepts the name file placed on the [locale dir](https://github.com/logaretm/vee-validate/tree/master/locale) of Vee-Validate repository without the extension. + +#### `rules` + +- Default: `undefined` + +If `undefined`, importing all rules. +When listed from [validation-rules](https://logaretm.github.io/vee-validate/api/rules.html#validation-rules), importing it. -The `lang` option accepts the name file placed on the [locale dir](https://github.com/baianat/vee-validate/tree/master/locale) of Vee-Validate repository without the extension. +```js +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](https://github.com/baianat/vee-validate/tree/master/locale) are different, set `locale` object to convert locale code. +If nuxt-i18n's locale and Vee-Validate's [locale](https://github.com/logaretm/vee-validate/tree/master/locale) are different, set `locale` object to convert locale code. ```js nuxti18n: { @@ -61,8 +93,36 @@ nuxti18n: { } ``` -**notice:** If you use nuxt-i18n module, declare the nuxt-validate module at before it. +:warning: **notice:** If you use nuxt-i18n module, declare the nuxt-validate module at before it. ## Documentation -Read the [official Vee-Validate documentation and demos](https://baianat.github.io/vee-validate/). +Read the [official Vee-Validate documentation and demos](https://logaretm.github.io/vee-validate/). + +## FAQ + +### How to add custom validation methods? + +We recommend using plugins. + +`nuxt.config.js` + +```js +module.exports = { + plugins: ["~plugins/validate.js"], +} +``` + +`plugins/validate.js` + +```js +import { extend } from "vee-validate"; + +extend("my-validation", { + message: "This {_field_} is invalid.", + validate: value => { + // ... + return true; + } +}); +``` diff --git a/templates/plugin.js b/templates/plugin.js index 6076496..e4127de 100644 --- a/templates/plugin.js +++ b/templates/plugin.js @@ -38,7 +38,6 @@ const getLocale = (opt, locale) => { } <% if (options.nuxtValidateOptions && Object.keys(options.nuxtValidateOptions).length > 0) { %> -// https://github.com/logaretm/vee-validate/blob/master/docs/configuration.md configure(<%= JSON.stringify(options.nuxtValidateOptions) %>); <% } %>