Reputation: 670
I'm using VeeValidate and works perfectly for English (which is default) however if I try to use any other language I'm getting an error saying "Property 'locale' does not exist on type 'Validator'."
Here is my code:
import VeeValidate from 'vee-validate';
import french from 'vee-validate/dist/locale/fr';
Vue.use(VeeValidate);
@Component
export default class TestTest extends Vue {
locale: any; // I have tried locale: string='fr';
nextLocale() {
return this.locale === 'en' ? 'French' : 'English';
}
changeLocale() {
this.locale = this.$validator.locale === 'fr' ? 'en' : 'fr';
this.$validator.setLocale(this.locale);
}
created() {
this.$validator.updateDictionary({
fr: {
messages: french.messages,
}
})
}
// other none related code...
}
Upvotes: 0
Views: 1615
Reputation: 462
According to:
http://vee-validate.logaretm.com/localization.html#api
To dynamically change the locale in your component, you have to call localize like so
this.$validator.localize('fr', french)
And it should work just fine (you don't need to call updateDictionary as the call above is already doing this)
Upvotes: 2