I have the following inside a component:
<v-form v-model="valid" ref="form" class="px-3">
<v-text-field label="First Name" v-model="firstname" :rules="inputRules"></v-text-field>
<v-text-field label="Last Name" v-model="lastname" :rules="inputRules"></v-text-field>
<v-text-field label="Email" v-model="email"></v-text-field>
<v-btn :loading="loading" flat class="success mx-0 mt-3" @click="submit">Create Person</v-btn>
</v-form>
Script:
export default {
data() {
return {
valid: true,
firstname: '',
lastname: '',
email: '',
loading: false,
dialog: false,
inputRules: [
v => v.length >= 2 || 'Minimum length is 2 characters'
]
}
},
methods: {
submit() {
if(this.$refs.form.validate()) {
this.loading = true;
const person = {
firstname: this.firstname,
lastname: this.lastname,
email: this.email
};
sendToMyDB(person).then(()=>{
this.loading = false;
this.dialog = false;
this.$refs.form.reset();
})
}
}
}
}
So Im submitting the form data to my database then in the success promise Im using this.$refs.form.reset(); to reset my form.
However, I am getting an error messages immediately and on each subsequent submit:
"[Vue warn]: Error in nextTick: "TypeError: Cannot read property 'length' of undefined"
and
TypeError: Cannot read property 'length' of undefined