8

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>

1 Answer 1

9

() => 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>

Updated Answer with working example

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the hint. Now what makes me wonder is that I still get the default error messages from vee-validate. I've attached the HTML code for reference, maybe there is something else I do incorrectly?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.