|
20 | 20 | <ui-tag |
21 | 21 | :value="option.label || option" |
22 | 22 | :label="'Unselect' + option.label || option" |
23 | | - @click="removeSelection(index)"> |
| 23 | + @click="removeSelection(option)"> |
24 | 24 | </ui-tag> |
25 | 25 | </li> |
26 | 26 | </ul> |
|
115 | 115 | search: '', |
116 | 116 | highlighted: 0, |
117 | 117 | // 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, |
119 | 119 | } |
120 | 120 | }, |
121 | 121 |
|
|
237 | 237 |
|
238 | 238 | watch: { |
239 | 239 | 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 |
245 | 241 | this.resetHighlighted(); |
246 | 242 | }, |
247 | 243 |
|
248 | 244 | selection(value) { |
249 | | - this.$emit('input', _.isArray(value) ? _.join(value, ',') : value) |
| 245 | + this.$emit('input', value) |
250 | 246 | }, |
251 | 247 |
|
252 | 248 | search(value) { |
|
302 | 298 | } |
303 | 299 | }, |
304 | 300 |
|
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) |
306 | 306 | this.selection.splice(index, 1) |
307 | 307 | }, |
308 | 308 |
|
309 | 309 | toggleSelection(option) { |
310 | 310 | if (this.inSelection(option)) { |
311 | | - this.removeSelection(_.indexOf(this.selection, option)) |
| 311 | + this.removeSelection(option) |
312 | 312 | } else { |
313 | 313 | this.addSelection(option) |
314 | 314 | } |
|
0 commit comments