admin管理员组文章数量:1203209
My form has a name input and an alias input. They are in a Primevue Form inside a FormField and both have a resolver that checks for required input.
When a name is entered in the name field the value is being copied by the program to the alias field. In this case the alias resolver isn't being called and the alias field shows an error 'required' message.
When entering a value manually in the input the resolver is being called and the 'required' message appears or disappears depending on alias having a value or not.
Question is when setting values programmatically how can I trigger the validation to be performed that is set on the respective FormFields?
My form has a name input and an alias input. They are in a Primevue Form inside a FormField and both have a resolver that checks for required input.
When a name is entered in the name field the value is being copied by the program to the alias field. In this case the alias resolver isn't being called and the alias field shows an error 'required' message.
When entering a value manually in the input the resolver is being called and the 'required' message appears or disappears depending on alias having a value or not.
Question is when setting values programmatically how can I trigger the validation to be performed that is set on the respective FormFields?
Share Improve this question edited Jan 22 at 7:47 DarkBee 15.6k8 gold badges70 silver badges114 bronze badges asked Jan 22 at 7:37 ReneRene 10.5k5 gold badges36 silver badges48 bronze badges1 Answer
Reset to default 0Found a way to trigger Primevue FormField validation after setting the input value programmatically.
Give the FormField a ref property:
<FormField ref="alias"
In the code where you set the value of the alias field you can now reference the internal state values of the input. These need to be changed to trigger validation.
$_setAlias() {
this.record.alias = this.record.name; // Set alias equal to the name of the record
this.$refs.news.field.states.dirty = true; // Set some internal status fields
this.$refs.alias.field.states.touched = true;
this.$refs.alias.field.states.pristine = false;
this.$refs.alias.field.states.value = this.record.title; // Set internal field value.
},
With these settings field validation is triggered. Haven't figured out if setting only some of these values works as well. That needs further investigation.
本文标签: primevueHow to validate input when value is set programmatically in form validationStack Overflow
版权声明:本文标题:primevue - How to validate input when value is set programmatically in form validation? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738580978a2101160.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论