@@ -3,7 +3,7 @@ import deepClone from './utils'
3
3
function includes ( str , query ) {
4
4
if ( ! str ) return false
5
5
const text = str . toString ( ) . toLowerCase ( )
6
- return text . indexOf ( query ) !== - 1
6
+ return text . indexOf ( query . trim ( ) ) !== - 1
7
7
}
8
8
9
9
function filterOptions ( options , search , label ) {
@@ -274,7 +274,7 @@ module.exports = {
274
274
const search = this . search || ''
275
275
const normalizedSearch = search . toLowerCase ( )
276
276
277
- let options = this . options
277
+ let options = this . options . concat ( )
278
278
279
279
if ( this . internalSearch ) {
280
280
options = this . groupValues
@@ -306,14 +306,14 @@ module.exports = {
306
306
: options . map ( element => element . toString ( ) . toLowerCase ( ) )
307
307
} ,
308
308
currentOptionLabel ( ) {
309
- return this . getOptionLabel ( this . internalValue [ 0 ] ) + ''
309
+ return this . multiple ? '' : this . getOptionLabel ( this . internalValue [ 0 ] ) + ''
310
310
}
311
311
} ,
312
312
watch : {
313
- 'internalValue' ( ) {
314
- if ( this . resetAfter ) {
315
- this . internalValue = [ ]
313
+ 'internalValue' ( newVal , oldVal ) {
314
+ if ( this . resetAfter && this . internalValue . length ) {
316
315
this . search = ''
316
+ this . internalValue = [ ]
317
317
}
318
318
this . adjustSearch ( )
319
319
} ,
@@ -328,6 +328,11 @@ module.exports = {
328
328
}
329
329
} ,
330
330
methods : {
331
+ getValue ( ) {
332
+ return this . multiple
333
+ ? deepClone ( this . internalValue )
334
+ : deepClone ( this . internalValue [ 0 ] )
335
+ } ,
331
336
/**
332
337
* Filters and then flattens the options list
333
338
* @param {Array }
@@ -351,7 +356,7 @@ module.exports = {
351
356
) ( options )
352
357
} ,
353
358
updateSearch ( query ) {
354
- this . search = query . trim ( ) . toString ( )
359
+ this . search = query . toString ( )
355
360
} ,
356
361
/**
357
362
* Finds out if the given query is already present
@@ -424,10 +429,7 @@ module.exports = {
424
429
this . internalValue = [ option ]
425
430
}
426
431
this . $emit ( 'select' , deepClone ( option ) , this . id )
427
- const value = this . multiple
428
- ? this . internalValue
429
- : this . internalValue [ 0 ]
430
- this . $emit ( 'input' , deepClone ( value ) , this . id )
432
+ this . $emit ( 'input' , this . getValue ( ) , this . id )
431
433
432
434
if ( this . closeOnSelect ) this . deactivate ( )
433
435
}
@@ -451,10 +453,7 @@ module.exports = {
451
453
452
454
this . internalValue . splice ( index , 1 )
453
455
this . $emit ( 'remove' , deepClone ( option ) , this . id )
454
- const value = this . multiple
455
- ? this . internalValue
456
- : this . internalValue [ 0 ]
457
- this . $emit ( 'input' , deepClone ( value ) , this . id )
456
+ this . $emit ( 'input' , this . getValue ( ) , this . id )
458
457
} ,
459
458
/**
460
459
* Calls this.removeElement() with the last element
@@ -510,10 +509,7 @@ module.exports = {
510
509
} else {
511
510
this . $el . blur ( )
512
511
}
513
- const value = this . multiple
514
- ? this . internalValue
515
- : this . internalValue [ 0 ]
516
- this . $emit ( 'close' , deepClone ( value ) , this . id )
512
+ this . $emit ( 'close' , this . getValue ( ) , this . id )
517
513
} ,
518
514
/**
519
515
* Adjusts the Search property to equal the correct value
0 commit comments