radiorz
radiorz

Reputation: 1879

when i close the form dialog and reopen,the form is still red and isn’t initialized。

i write a form like this with vuetify.

   <v-form>
          <v-text-field
            autocomplete="off"
            v-model="model.password"
            :label="formschema.password.label"
            :rules="[rules.required, rules.min]"
            :append-icon="formschema.password.show ? 'mdi-eye' : 'mdi-eye-off'"
            @click:append="formschema.password.show = !formschema.password.show"
            :type="formschema.password.show ? 'text' : 'password'"
            required
          ></v-text-field>
          <v-text-field
            autocomplete="off"
            v-model="model.newpassword"
            :label="formschema.newpassword.label"
            :rules="[rules.required, rules.min]"
            :type="formschema.newpassword.show ? 'text' : 'password'"
            :append-icon="
              formschema.newpassword.show ? 'mdi-eye' : 'mdi-eye-off'
            "
            @click:append="
              formschema.newpassword.show = !formschema.newpassword.show
            "
            required
          ></v-text-field>
          <v-text-field
            autocomplete="off"
            v-model="model.comfirmpassword"
            :label="formschema.comfirmpassword.label"
            :rules="[rules.required, rules.min]"
            :append-icon="
              formschema.comfirmpassword.show ? 'mdi-eye' : 'mdi-eye-off'
            "
            @click:append="
              formschema.comfirmpassword.show = !formschema.comfirmpassword.show
            "
            :type="formschema.comfirmpassword.show ? 'text' : 'password'"
            required
          ></v-text-field>
        </v-form>

when i close it (the form is in an dialog),i clean the data, but when i reopen it ,it will return errrors:

"TypeError: Cannot read property 'length' of null"

please help me .how can i reset the form data but not get the error ?

i clean my form just let the model bind to form's items = default model. such as:

this.model = this.defaultmodel

Upvotes: 1

Views: 1446

Answers (1)

Jason Landbridge
Jason Landbridge

Reputation: 1402

I think this is what you're looking for:

https://vuetifyjs.com/en/components/forms/#validation-with-submit-clear

You have to basically call this.$refs.form.resetValidation() after you have closed the dialog.

Upvotes: 2

Related Questions