0

I have an input and a select in my VUE application that are shown depending on the selection of a previous input. If I insert values and change the initial input selection, I hide the second input and select, to restart the form. The problem comes when I restart the form and I still get the selected values on the first load. I'm trying to reset the values but none of the methods I've found in similar case reviews works fine. Here's my select and my input that i want to reset values

              <h1 v-if="this.isSelected"> What's your selection ?</h1>
              <select
                ref="item"
                class="form-control"
                id="selectedItem"
                v-model="itemFormInfo.selectedItem"
                @change="onChangeItem($event)">
                <option v-for="item in filteredItem" v-bind:key="item.name">{{ item.name }}</option>
              </select>
              <div v-show="this.isItemSelected">
                <h1>what's your item name ?</h1>
                <input
                  type="text"
                  id="name"
                  ref="itemName"
                  class="form-control fields"
                  style="text-transform: capitalize"
                  v-model="itemFormInfo.name"
                  @keypress="formChange($event)"
                />
                <div class="loader-spinner" v-if="loading">
                  <app-loader/>
                </div>
              </div>



and here's my method where I have tried the reset and document.getElementById('').value("") methods;

    onChangeSpecie(event) {
      let specie = event.target._value;
      this.specieName = this.getSpecieName(specie);
      this.breedName = this.getBreedName(specie);
      this.$refs.breed.focus();
      if (this.isBreedSelected = true) {
        this.isBreedSelected = false;
        this.isNameCompleted = false;
        this.isLoaderFinished = false;
        this.$refs.animalName.item()

      }
    },


If I print by console I see how the value is emptied but the input appears with the written value until I focus on the . How do I stop it from appearing? in neither method does it erase my previous values showing on the input. what am I doing wrong? thank you all for your help and time in advance

1
  • if (this.isBreedSelected = true) is a bug. You're assigning this.isBreedSelected instead of comparing it to true. It should be: if (this.isBreedSelected === true) Commented Oct 3, 2020 at 4:10

1 Answer 1

1

I believe you need to null the model not the target element's value.

this.itemFormInfo.name = null
Sign up to request clarification or add additional context in comments.

1 Comment

I had to match it to "", because then I have to recover the .length in another function and if I match it to null it returns an error, but you have solved my problem. Thank you very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.