ATT
ATT

Reputation: 337

how check form is valid and disable submit button in vuejs2?

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

Answers (1)

Anik Saha
Anik Saha

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

Related Questions