Vee-validate: "[vee-validate]: Extension Error: There is an existing validator with the same name 'xxxx'."

Created on 15 Jan 2017  路  3Comments  路  Source: logaretm/vee-validate

created() {
    this.$validator.extend('verify_image',{
        getMessage:(filedName)=>`${filedName} .`,
            validate: (value) => {
                return value
            }
        });

when I extend a custom rule in a component and create multiple instance,
the console throw an error like this

Does need custom rule a local scope?
or exist some function to check if a name has been registered?

Most helpful comment

Validators all share the same scope for the following: rules, dictionary, and locale

the error occurs because the created() cycle is executed more than one time, probably because you are using a component more than once in a page, or that you are visiting the route that triggers that component more than one time.

To avoid this issue you should extend the validator in your entry file main.js where your application code is being bootstrapped, that way you make sure there is only one instance of that custom rule. which is recommended either way since you can use that rule anywhere in your code.

or use $validator.remove(ruleName) to remove a rule from the list of validations if it exists.

I probably should add a method to check if a rule exists.

All 3 comments

I checked the source code, seems Rules is an external Object and not belong validator instance, so have no possible to call it inside this.$validator

static _guardExtend(name, validator) {
        if (Rules[name]) {
            throw new ValidatorException(
                `Extension Error: There is an existing validator with the same name '${name}'.`
            );

Validators all share the same scope for the following: rules, dictionary, and locale

the error occurs because the created() cycle is executed more than one time, probably because you are using a component more than once in a page, or that you are visiting the route that triggers that component more than one time.

To avoid this issue you should extend the validator in your entry file main.js where your application code is being bootstrapped, that way you make sure there is only one instance of that custom rule. which is recommended either way since you can use that rule anywhere in your code.

or use $validator.remove(ruleName) to remove a rule from the list of validations if it exists.

I probably should add a method to check if a rule exists.

Yes, I used a listable component in one page, resolved

Was this page helpful?
0 / 5 - 0 ratings

Related issues

the94air picture the94air  路  3Comments

parweb picture parweb  路  3Comments

triffer picture triffer  路  3Comments

jagasan picture jagasan  路  3Comments

YamenSharaf picture YamenSharaf  路  3Comments