0

I am having a hard time retrieving values from a multi-select box in Vue. After the user has selected any number of values, I want to retrieve the values and submit to a data source. No luck so far. Here's an excerpt of my code below.

<div id="app">
   <select multiple v-bind:data-id="program.id" :disabled="!program.editable" v-model="program.dropDowns">
       <option>Microsoft</option>
       <option>IBM</option>
       <option>Google</option>
       <option>Apple</option>
   </select>
</div>
getPrograms: function() {
      axios.get("https://my-json-server.typicode.com/isogunro/jsondb/Programs").then((response) => {
          this.programs = response.data.map(row => ({
            ...row,
            dateFormatted: toDDMMYY(row.Date),
            editable: false,
            dropDowns: ["Apple","Google"]
          }));
        console.log(this.programs)
        })
        .catch(function(error) {
          console.log(error);
        });
}

Any help would be much appreciated. Here's the actual pen

4
  • Where is it that you are submitting the data to a datasource? Commented Nov 21, 2019 at 3:18
  • I'm submitting to a list. I initially posted relevant code but notified me to trim it. Commented Nov 22, 2019 at 1:08
  • Oh I see! Let me know if my answer was of any help. Commented Nov 22, 2019 at 2:49
  • Actually, it didn't really work. Edit the company column and select more than one value and click save. It's not captureing the values. codepen.io/isogunro/pen/bGGrWZG?editors=1011 Commented Nov 22, 2019 at 12:12

2 Answers 2

2

Just you have assigned drop down data wrongly , Need to change like below:

Little change in template:

<button v-else  @click="saveItem(program)">save</button>

and saveItem() method like below:

saveItem (program) {
     program.isReadOnly = true
     program.editable = false
     console.log(program)
     alert(program.dropDowns)
    }
Sign up to request clarification or add additional context in comments.

2 Comments

I'm sorry. I thought it was working but that didn't really work. Edit the company column and select more than one value and click save. It's not captureing the values. codepen.io/isogunro/pen/bGGrWZG?editors=1011
still it is working, but now you have changed your code, as per your current code, you have to change the saveItem method like : saveItem (program) { program.isReadOnly = true console.log(program) alert("New Value: "+program.company) alert("Previous Value: "+program.company) }
1

The problem is that you are not passing anything to the saveItem function, so no program was being sent.

You just have to replace saveItem for saveItem(program) and that should do the trick.

2 Comments

By the way, the part of the code I'm talking about is not written in your post. You should have all your relevant code inside your post, not just in a codepen.
Right. <button v-else @click="saveItem(program)">save</button>

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.