Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation state of overall form #29

Closed
Doogiemuc opened this issue Dec 15, 2016 · 2 comments
Closed

Validation state of overall form #29

Doogiemuc opened this issue Dec 15, 2016 · 2 comments
Labels

Comments

@Doogiemuc
Copy link

I really like your idea of implementing validation as a mixing instead of configuring it with vue directives in the tempaltes, as most others do.

But one question: I want the "Save" button in my forms to be deactivated until the whole form, ie all fields in the form, become valid. How would I query for this "overall validity" in your library?

Do I need to create a 'validation group' for the whole form? Shouldn't there be a global $isValid boolean in the returned $v ?

@mubaidr
Copy link

mubaidr commented Dec 15, 2016

You have to use validation groups for that purpose. I have done exactly same functionality in my project, please have a look at this: https://github.com/mubaidr/SPA-asp.net-api-vuejs-/tree/master/MBO

(check signup component)

@furey
Copy link

furey commented Dec 16, 2016

@Doogiemuc

The root $v object contains $invalid, $dirty and $error values, just like all the keys inside of it:

{
    "example-data-key": {
        "required": true,
        "$invalid": true,
        "$dirty": true,
        "$error": true
    },
    "$invalid": true,
    "$dirty": true,
    "$error": true
}

For your save button, you could simply bind the disabled attribute like so:

<button :disabled="$v.$invalid">Save</button

Like @mubaidr mentioned, you could also use validation groups if your logic depends on specific fields being valid before enabling.

Cheers.

@Frizi Frizi closed this as completed Dec 22, 2016
@Frizi Frizi added the help label Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants