Vue2 plus vee-validate - how to configure error messages without ES6?

I try (without success) to customize error messages for vee-validate, but all the examples on the website use ES6. I can argue that this is possible without it, so any suggestions about what I'm doing wrong are appreciated :)

<script>
    const messages = {
      en: {
        confirmed: "Your password is not confirmed",
        email: "I really dont like your email"
      }
    };

    Vue.use(VeeValidate);
    var app = new Vue({
        el: '#app'            
    });
    app.$validator.updateDictionary(messages);
</script>

There are no errors, just the default messages are used.

UPDATE

Below is my HTML code.

<input type="text" name="email" v-validate data-vv-rules="required|email" />
<span v-show="errors.has('email')">{{ errors.first('email') }}</span>

<input type="password" name="password" v-validate data-vv-rules="required" />
<span v-show="errors.has('password')">{{ errors.first('confirmation')}} </span>  
<input type="password" name="confirmation" v-validate data-vv-rules="confirmed:password"/>
<span v-show="errors.has('confirmation')">{{ errors.first('confirmation')}}/span>
+4
source share
1 answer

() =>is the syntax for defining a function in ES6 , therefore for converting the vee-validate syntax to older Javascript.

therefore from the documentation :

alpha: () => 'Some English Message'

will be equivalent

alpha: function() {
  return 'Some English Message'
}

Similarly, you must make the following changes:

<script>
    const messages = {
      en: {
        confirmed: function () { 
            return "Your password is not confirmed"
        },
        email: function () { 
            return "I really dont like your email"
        }
      }
    };

    Vue.use(VeeValidate);
    var app = new Vue({
        el: '#app'            
    });
    app.$validator.updateDictionary(messages);
</script>

. vee-validate:

<script>
const dictionary = {
  en: {
    messages: {
      confirmed: function () { 
        return "Your password is not confirmed"
      },
      email: function () { 
        return "I really dont like your email"
      }
    }
  }
};

VeeValidate.Validator.updateDictionary(dictionary);
Vue.use(VeeValidate);
Vue.config.debug = true;
var App = new Vue({
    el: '#app'
});
</script>

fiddle.

+6

Source: https://habr.com/ru/post/1663388/


All Articles