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

Automatic $touch() #34

Closed
andrisi opened this issue Dec 19, 2016 · 2 comments
Closed

Automatic $touch() #34

andrisi opened this issue Dec 19, 2016 · 2 comments

Comments

@andrisi
Copy link

andrisi commented Dec 19, 2016

Could you include an option to automatically run validators on any change? As I unserstand I need to add an something like @change="$v.email.$touch()" to every input I have and this kind of kills the mood. Should be optional obviously, but it's also a nobrainer that it would be useful in many cases. Thanks.

@Frizi
Copy link
Contributor

Frizi commented Dec 19, 2016

Validators are running every time. If you don't need the $dirty flag, you can just ignore $touch and $reset. Validators and $valid will still work.

There is a reason it's not done automatically. First of all, validators are decoupled from the forms. You can validate anything, it doesn't have to be an input field. Second, you may want to listen to a totally different event. If you want to automate stuff for yourself, just make a component.

<template>
  <input type="text" :value="value" @input="$emit('input', $event); v.$touch()" />
</template>
<script>
  export default {
    name: 'MyInput',
    props: ['value', 'v']
  }
</script>

and just use it like that

<my-input v-model="email" :v="$v.email" />

@andrisi
Copy link
Author

andrisi commented Dec 20, 2016

Thanks.

@andrisi andrisi closed this as completed Dec 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants