I am trying (without a success) to customize error messages for vee-validate, but all the examples on the website use ES6. I can bet it's doable also without it, so any suggestions what I am 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, simply 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>
() =>
is syntax to define function in ES6, so to convert syntax of vee-validate to older Javascript.
so from the documentation:
alpha: () => 'Some English Message'
will be equivalent of
alpha: function() {
return 'Some English Message'
}
Similarly, you have to make 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>
There seems to be some syntax errors in the above code, Following is the working code with latest vee-validate syntax:
<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>
Working fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With