Reputation: 337
I want to check if form is valid using vee-validate. I am currently doing it like this:
<button type="submit" :disabled="errors.count()">
But when the form is created and not validated yet, errors.count() return 0
, meaning that the button stays enabled until the user modifies a field.
Is there any way to validate it at start?
Upvotes: 1
Views: 2742
Reputation: 4494
I dont find any vee-validate api for that. So that's why I have to fixed this issue by doing this way.
Vue.component("form", {
computed: {
isFormInvalid:function () {
return this.errors.count() > 0 || !(Object.keys(this.fields).some(key => this.fields[key].dirty));
}
}
});
<button type="submit" :disabled="isFormInvalid">
Upvotes: 5