Reputation: 981
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
Upvotes: 0
Views: 167
Reputation: 2823
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)
}
Upvotes: 2
Reputation: 1966
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.
Upvotes: 1