How would I do the following?
I'm trying to make the required message for firstName be:
Please enter your first name.
and for city:
Please enter the city.
So far I have:
const dictionary = {
en: {
messages: {
required: (field) => {
if (field === 'firstName') {
return `Please enter your ${field}.`
} else if (field === 'city') {
return `Please enter the ${field}.`
}
return `Please enter a ${field}.`
},
},
},
}
Object.keys(veeRules).forEach(k => Validator.extend(k, veeRules[k]))
Validator.localize('en', veeEn)
Vue.use(VeeValidate, { inject: false, dictionary })
But this doesn't seem correct.
You could assign specific error messages to specific fields:
const dictionary = {
en: {
custom: {
firstName: {
required: 'Please enter your first name.'
},
city: {
required: 'Please enter the city.'
}
}
}
}
Object.keys(veeRules).forEach(k => Validator.extend(k, veeRules[k]))
Validator.localize('en', veeEn)
Vue.use(VeeValidate, { inject: false, dictionary })
Hi @logaretm I'm trying this out but I keep getting: "Can't find variable: veeRules". I'm obviously doing something wrong. Please can you give me pointers?
Never mind--I fixed this myself now.
@elujoba I know that you fixed it, but more info is here: https://github.com/baianat/vee-validate/issues/1329
@logaretm Thanks a million!
Most helpful comment
You could assign specific error messages to specific fields: