admin管理员组文章数量:1425662
I'm trying to access the validation flags from a puted prop:
puted: {
isFormValid() {
let isValid = this.$validator.fields.some(field => {
console.log(field.flags);
return field.flags.touched; || field.flags.invalid;
});
console.log("isValid", isValid);
return isValid;
}
},
But this gives an error: "TypeError: this.$validator.fields.some is not a function"
So then I figured I would iterate over the observable
:
let isValid = Array.from(this.$validator.fields).some(field => {
console.log(field.flags);
return field.flags.touched; //|| field.flags.invalid;
});
Yay! Progress! No more error. But it doesn't repute when I change the form input values.
So how can I do this?
I'm trying to access the validation flags from a puted prop:
puted: {
isFormValid() {
let isValid = this.$validator.fields.some(field => {
console.log(field.flags);
return field.flags.touched; || field.flags.invalid;
});
console.log("isValid", isValid);
return isValid;
}
},
But this gives an error: "TypeError: this.$validator.fields.some is not a function"
So then I figured I would iterate over the observable
:
let isValid = Array.from(this.$validator.fields).some(field => {
console.log(field.flags);
return field.flags.touched; //|| field.flags.invalid;
});
Yay! Progress! No more error. But it doesn't repute when I change the form input values.
So how can I do this?
Share Improve this question edited Oct 7, 2019 at 6:36 tony19 139k23 gold badges278 silver badges348 bronze badges asked Oct 1, 2019 at 13:14 ShamoonShamoon 43.7k101 gold badges332 silver badges628 bronze badges 2- I suggest you go throught this topic on official web site - logaretm.github.io/vee-validate/guide/…. I believe it will answer on all your questions – Pobepto Commented Oct 4, 2019 at 19:45
- I did. That’s how I came up with what I did. Problem is that it’s not working. – Shamoon Commented Oct 5, 2019 at 2:31
1 Answer
Reset to default 4 +50The v2 docs show an example that iterates this.fields
(instead of this.$validator.fields
) via Object.keys
:
// MyComponent.vue
export default {
// ...
puted: {
isFormDirty() {
return Object.keys(this.fields).some(key => this.fields[key].dirty);
}
},
//...
}
Using that example, your puted prop would be:
// MyComponent.vue
export default {
// ...
puted: {
isFormTouchedOrInvalid() {
return Object.keys(this.fields).some(key => this.fields[key].touched || this.fields[key].invalid);
}
},
//...
}
v2 demo
In v3, you could use the <ValidationProvider>
ponent to easily access the validation flags in the template:
<ValidationProvider rules="required" v-slot="{ touched, invalid }">
<pre>touched:{{touched}} invalid:{{invalid}}</pre>
<input type="email" v-model="value">
</ValidationProvider>
v3 demo
本文标签:
版权声明:本文标题:javascript - With VeeValidate, how can I see if a field has been touched and is valid? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745389863a2656547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论