Vee-validate: Error in localization custom rules

Created on 17 Dec 2017  ยท  3Comments  ยท  Source: logaretm/vee-validate

Versions:

  • VueJs: 2.5.11
  • Vee-Validate: 2.0.0-rc.27

Description:

After update vee-validate I get error Uncaught Error: [vee-validate] Extension Error: The validator 'login' object must have a 'getMessage' method or string.

Steps To Reproduce:

Validator.extend('login', {
    messages: {
        en() {
            return en.translation.userNotExistCredentials;
        },
        he() {
            return he.translation.userNotExistCredentials;
        },
    },
    async validate(value) {
        return {
            valid: value !== 0,
        };
    },
});

If I add getMessage, it's works, but object messages ignores.

Validator.extend('login', {
    messages: {
        en() {
            return en.translation.userNotExistCredentials;
        },
        he() {
            return he.translation.userNotExistCredentials;
        },
    },
    async validate(value) {
        return {
            valid: value !== 0,
        };
    },
    getMessage() {
        return en.translation.userNotExistCredentials;
    },
});
โ” question

Most helpful comment

I believe this shouldn't be closed until the documentation is corrected

All 3 comments

Sorry about that, we had a breaking change introduced in rc.26 with the introduction of vue-i18n support:

messages object will no longer be accepted in Validator.extend, you should use localize API from now on.

You should use Validator.localize to merge your messages instead.

I believe this shouldn't be closed until the documentation is corrected

docs have been updated, sorry about that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

7immer picture 7immer  ยท  3Comments

the94air picture the94air  ยท  3Comments

HunterJS-bit picture HunterJS-bit  ยท  3Comments

triffer picture triffer  ยท  3Comments

ash0080 picture ash0080  ยท  3Comments