Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
14
rated 0 times [  20] [ 6]  / answers: 1 / hits: 5472  / 4 Years ago, fri, march 20, 2020, 12:00:00

I have a basic input text field and want to reset it after submitting. When resetting it I currently update its v-model to an empty string. Unfortunately this triggers my input rules and renders an error message.



Code example:



<div id=app>
<v-app>
<v-text-field v-model=text :rules=[value => !!value || 'Required']></v-text-field>
<v-btn @click=text = ''>submit and reset</v-btn>
</v-app>
</div>

new Vue({
el: '#app',
vuetify: new Vuetify(),
data() {
return {
text:
};
}
})


Is there a way I can empty the field without triggering the rule? I mean it behaves correctly and I would expect that, but when I click on the button I want to reset the field to its initial state.


More From » vue.js

 Answers
2

If you put it within a form you can call form.reset()



<v-form
ref=form
>
<v-text-field v-model=text :rules=[value => !!value || 'Required']></v-text-field>
<v-btn @click=submit>submit and reset</v-btn>
</v-form>


methods : {
submit () {
this.$refs.form.reset()
}
}


the example codepen used in the docs: https://codepen.io/ellisdod/pen/jOPpzOO



https://vuetifyjs.com/en/components/forms/


[#4427] Wednesday, March 18, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrellhunterm

Total Points: 82
Total Questions: 109
Total Answers: 98

Location: Vietnam
Member since Sun, Oct 18, 2020
4 Years ago
terrellhunterm questions
Mon, Aug 31, 20, 00:00, 4 Years ago
Mon, Aug 5, 19, 00:00, 5 Years ago
Thu, Apr 4, 19, 00:00, 5 Years ago
Mon, Mar 11, 19, 00:00, 5 Years ago
;