What do you have in your condole if you add console.log(this.selected); at the beginning of the addState() method ?
Moving items between 2 multiple select elements with our id
I'm trying to integrate shipping zones (country to state) where a user can load a country states from json object to display list of states on a multiple select html element.
// my countries to states json array
{
"name": "United States",
"iso3": "USA",
"iso2": "US",
"states": [
{
"name": "Alabama",
"state_code": "AL"
},
{
"name": "Alaska",
"state_code": "AK"
},
...
]
},{
"name": "Uruguay",
"iso3": "URY",
"iso2": "UY",
"states": [
{
"name": "Artigas Department",
"state_code": "AR"
},
...
on same page i have 2 multiple select html where user can select multiple items from states to add them to selected shipping zones list.
// List of states in a country
<select multiple v-model="selected" @dblclick="addState">
<option v-for="(state, index) in states">{{state.name}}</option>
</option>
</select>
// this is the selected shipping states
<select multiple v-model="selected_zones" @dblclick="removeState">
<option v-for="zone in zones">
{{ zone }}
</option>
</select>
to programatically move clicked items i have this function
addState() {
if(!this.selected.length) return;
for(let i=this.selected.length;i>0;i--) {
let idx = this.states.indexOf(this.selected[i-1]);
this.states.splice(idx, 1);
this.selected_zones.push(this.selected[i-1]);
this.selected.pop();
}
},
As a result i can see that only last element in the states array is getting moved to selected_zones object regardless which item is getting click on the states array.
is there is any way to correct this issue, i need the user to be able to move click items not last item in state object.
Any ideas
Please or to participate in this conversation.