logaretm / vee-validate

✅ Painless Vue forms
https://vee-validate.logaretm.com/v4
MIT License
10.83k stars 1.27k forks source link

How to custom error message of 'between' ? #1538

Closed jiazehua closed 6 years ago

jiazehua commented 6 years ago

Versions

Describe the bug

const dict = {
  zh_CN: {
    messages: {
      required: name => `you have to input it`,
      between: name => `wrong`,
    }
  } 
}
Validator.localize(dict)

For example, I made my own rules like that, but i don't know how to setup with the between , I can not get the range what i set like that way ↑

logaretm commented 6 years ago

Messages can be either functions or strings, functions allow you to use the parameters sent to the rule ordered in an array as the second argument.

const betweenMessage = (name, params) => {
  console.log(params[0]); // the min value
  console.log(params[1]); // the max value
};

Array destructing allows you to re-write this in a better way:

const betweenMessage = (name, [min, max]) => {
  console.log(min); // the min value
  console.log(max); // the max value
};

For reference, you can check the English locale file which covers all rules, so you may find it useful as a documentation for any locale specific issues.