Skip to content

Commit abe087e

Browse files
committed
fix bug for Select when allow multiple value
1 parent a4b1da7 commit abe087e

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

resources/js/ui/Select/Select.vue

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<ui-tag
2121
:value="option.label || option"
2222
:label="'Unselect' + option.label || option"
23-
@click="removeSelection(index)">
23+
@click="removeSelection(option)">
2424
</ui-tag>
2525
</li>
2626
</ul>
@@ -115,7 +115,7 @@
115115
search: '',
116116
highlighted: 0,
117117
// assuming selection is a string or a number only
118-
selection: _.isString(this.value) ? this.value.split(',') : [ _.toString(this.value) ],
118+
selection: _.isString(this.value) ? this.value.split(',') : this.value,
119119
}
120120
},
121121
@@ -237,16 +237,12 @@
237237
238238
watch: {
239239
value(value) {
240-
if (_.isString(this.value)) {
241-
this.selection = this.value.split(',')
242-
} else if (_.isNumber(this.value)) {
243-
this.selection = [ _.toString(this.value) ]
244-
}
240+
this.selection = _.isString(value) ? value.split(',') : value
245241
this.resetHighlighted();
246242
},
247243
248244
selection(value) {
249-
this.$emit('input', _.isArray(value) ? _.join(value, ',') : value)
245+
this.$emit('input', value)
250246
},
251247
252248
search(value) {
@@ -302,13 +298,17 @@
302298
}
303299
},
304300
305-
removeSelection(index) {
301+
removeSelection(option) {
302+
let index = _.findIndex(this.selection, (item) => {
303+
return option.value == item
304+
})
305+
console.log('remove', index, this.selection, option)
306306
this.selection.splice(index, 1)
307307
},
308308
309309
toggleSelection(option) {
310310
if (this.inSelection(option)) {
311-
this.removeSelection(_.indexOf(this.selection, option))
311+
this.removeSelection(option)
312312
} else {
313313
this.addSelection(option)
314314
}

0 commit comments

Comments
 (0)