Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

vuetify.js - Vuetify - validate programmatically added field values

I have seen the examples for a v-form here.(https://vuetifyjs.com/en/components/forms/).

They work as expected and produce error messages when a user inputs an invalid value.

I do not see how to validate programmatically. Below is a bare-bones example.

 <v-form v-model="valid" ref="form">
   <v-text-field v-model="foo" :rules="someRules" label="Test Field"/>
   <v-btn @clicked="changeValue">Change Value</v-btn>
 </v-form>
 ...
 changeValue() {
  this.foo = "somethingInvalid";
  // this.$refs.form.validate();
 }

If the user typed something invalid into the v-text-field a validation error would be shown (as expected). However if it is done via the changeValue() call the validation error is not shown.

I have also tried the forms validate() method, but it doesn't seem to do anything.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...