When I import moment in main.js, I meet the error " [vee-validate]: No such validator 'date_format' exists. " as before.
import moment from 'moment'
Vue.use(moment)
What went wrong?
Any help?
Solution:
The replay by @logaretm is useful. I used the first scheme.
yep, moment is not a vue plugin so you can't call Vue.use(moment);
Since you are using es6, You need to install them manually:
import Vue from 'vue';
import VeeValidate, { Validator } from 'vee-validate';
Validator.installDateTimeValidators(moment);
Vue.use(VeeValidate);
and that should be it, you can alternatively import moment in the global scope and it should install them automatically:
import moment from 'moment';
import Vue from 'vue';
import VeeValidate from 'vee-validate';
window.moment = moment;
Vue.use(VeeValidate);
@logaretm Thank you very much!
I has misconstrued the document of org site. Just this statement "If your setup contains momentjs globally, it will be installed automatically for all validator instances".
It solved my problem. Thanks!
Solution:
The replay by @logaretm is useful. I used the first scheme.
@logaretm Unless I've missed it, the info in you last comment about installing with moment should most definitively be in the docs. I've spent half the day trying to use the date_format validation rules. So this is the info that I strongly suggest should be added to the docs:
All date validation requires momentjs. It is not mentioned in the docs, I found out in issue #125. And the error messages are not clear. I suggest there should be a check to see if there is any valid datetime validators registered
The installation steps your wrote earlier. There is no mention of that in the docs as far as know of.
Other than that, great plugin. Very useful!
Ok, I found the steps to install the momentjs with installDateTimeValidators as a side note of the available rules list. I recommend this should be in the installation process as an optional step.
@lunfel It is included if moment is available globally, that is on the window object in most cases. I can add an option to provide moment at start up.
Also take a look at #615 which might help resolve any future issues coming from it.
Ah nice! #615 seems to fix the issue completely. It is true that there is a lot of confusion, because I expected the validation rules to work out-of-the-box. But with that in place, I will be way more clear.
Most helpful comment
yep, moment is not a vue plugin so you can't call
Vue.use(moment);Since you are using es6, You need to install them manually:
and that should be it, you can alternatively import moment in the global scope and it should install them automatically: