@@ -264,170 +264,6 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
264
264
return true ;
265
265
}
266
266
267
- $select . searchInput . on ( 'keyup' , function ( e ) {
268
-
269
- if ( ! KEY . isVerticalMovement ( e . which ) ) {
270
- scope . $evalAsync ( function ( ) {
271
- $select . activeIndex = $select . taggingLabel === false ? - 1 : 0 ;
272
- } ) ;
273
- }
274
- // Push a "create new" item into array if there is a search string
275
- if ( $select . tagging . isActivated && $select . search . length > 0 ) {
276
-
277
- // return early with these keys
278
- if ( e . which === KEY . TAB || KEY . isControl ( e ) || KEY . isFunctionKey ( e ) || e . which === KEY . ESC || KEY . isVerticalMovement ( e . which ) ) {
279
- return ;
280
- }
281
- // always reset the activeIndex to the first item when tagging
282
- $select . activeIndex = $select . taggingLabel === false ? - 1 : 0 ;
283
- // taggingLabel === false bypasses all of this
284
- if ( $select . taggingLabel === false ) return ;
285
-
286
- var items = angular . copy ( $select . items ) ;
287
- var stashArr = angular . copy ( $select . items ) ;
288
- var newItem ;
289
- var item ;
290
- var hasTag = false ;
291
- var dupeIndex = - 1 ;
292
- var tagItems ;
293
- var tagItem ;
294
-
295
- // case for object tagging via transform `$select.tagging.fct` function
296
- if ( $select . tagging . fct !== undefined ) {
297
- tagItems = $select . $filter ( 'filter' ) ( items , { 'isTag' : true } ) ;
298
- if ( tagItems . length > 0 ) {
299
- tagItem = tagItems [ 0 ] ;
300
- }
301
- // remove the first element, if it has the `isTag` prop we generate a new one with each keyup, shaving the previous
302
- if ( items . length > 0 && tagItem ) {
303
- hasTag = true ;
304
- items = items . slice ( 1 , items . length ) ;
305
- stashArr = stashArr . slice ( 1 , stashArr . length ) ;
306
- }
307
- newItem = $select . tagging . fct ( $select . search ) ;
308
- // verify the new tag doesn't match the value of a possible selection choice or an already selected item.
309
- if (
310
- stashArr . some ( function ( origItem ) {
311
- return angular . equals ( origItem , newItem ) ;
312
- } ) ||
313
- $select . selected . some ( function ( origItem ) {
314
- return angular . equals ( origItem , newItem ) ;
315
- } )
316
- ) {
317
- scope . $evalAsync ( function ( ) {
318
- $select . activeIndex = 0 ;
319
- $select . items = items ;
320
- } ) ;
321
- return ;
322
- }
323
- if ( newItem ) newItem . isTag = true ;
324
- // handle newItem string and stripping dupes in tagging string context
325
- } else {
326
- // find any tagging items already in the $select.items array and store them
327
- tagItems = $select . $filter ( 'filter' ) ( items , function ( item ) {
328
- return item . match ( $select . taggingLabel ) ;
329
- } ) ;
330
- if ( tagItems . length > 0 ) {
331
- tagItem = tagItems [ 0 ] ;
332
- }
333
- item = items [ 0 ] ;
334
- // remove existing tag item if found (should only ever be one tag item)
335
- if ( item !== undefined && items . length > 0 && tagItem ) {
336
- hasTag = true ;
337
- items = items . slice ( 1 , items . length ) ;
338
- stashArr = stashArr . slice ( 1 , stashArr . length ) ;
339
- }
340
- newItem = $select . search + ' ' + $select . taggingLabel ;
341
- if ( _findApproxDupe ( $select . selected , $select . search ) > - 1 ) {
342
- return ;
343
- }
344
- // verify the the tag doesn't match the value of an existing item from
345
- // the searched data set or the items already selected
346
- if ( _findCaseInsensitiveDupe ( stashArr . concat ( $select . selected ) ) ) {
347
- // if there is a tag from prev iteration, strip it / queue the change
348
- // and return early
349
- if ( hasTag ) {
350
- items = stashArr ;
351
- scope . $evalAsync ( function ( ) {
352
- $select . activeIndex = 0 ;
353
- $select . items = items ;
354
- } ) ;
355
- }
356
- return ;
357
- }
358
- if ( _findCaseInsensitiveDupe ( stashArr ) ) {
359
- // if there is a tag from prev iteration, strip it
360
- if ( hasTag ) {
361
- $select . items = stashArr . slice ( 1 , stashArr . length ) ;
362
- }
363
- return ;
364
- }
365
- }
366
- if ( hasTag ) dupeIndex = _findApproxDupe ( $select . selected , newItem ) ;
367
- // dupe found, shave the first item
368
- if ( dupeIndex > - 1 ) {
369
- items = items . slice ( dupeIndex + 1 , items . length - 1 ) ;
370
- } else {
371
- items = [ ] ;
372
- if ( newItem ) items . push ( newItem ) ;
373
- items = items . concat ( stashArr ) ;
374
- }
375
- scope . $evalAsync ( function ( ) {
376
- $select . activeIndex = 0 ;
377
- $select . items = items ;
378
-
379
- if ( $select . isGrouped ) {
380
- // update item references in groups, so that indexOf will work after angular.copy
381
- var itemsWithoutTag = newItem ? items . slice ( 1 ) : items ;
382
- $select . setItemsFn ( itemsWithoutTag ) ;
383
- if ( newItem ) {
384
- // add tag item as a new group
385
- $select . items . unshift ( newItem ) ;
386
- $select . groups . unshift ( { name : '' , items : [ newItem ] , tagging : true } ) ;
387
- }
388
- }
389
- } ) ;
390
- }
391
- } ) ;
392
- function _findCaseInsensitiveDupe ( arr ) {
393
- if ( arr === undefined || $select . search === undefined ) {
394
- return false ;
395
- }
396
- var hasDupe = arr . filter ( function ( origItem ) {
397
- if ( $select . search . toUpperCase ( ) === undefined || origItem === undefined ) {
398
- return false ;
399
- }
400
- return origItem . toUpperCase ( ) === $select . search . toUpperCase ( ) ;
401
- } ) . length > 0 ;
402
-
403
- return hasDupe ;
404
- }
405
- function _findApproxDupe ( haystack , needle ) {
406
- var dupeIndex = - 1 ;
407
- if ( angular . isArray ( haystack ) ) {
408
- var tempArr = angular . copy ( haystack ) ;
409
- for ( var i = 0 ; i < tempArr . length ; i ++ ) {
410
- // handle the simple string version of tagging
411
- if ( $select . tagging . fct === undefined ) {
412
- // search the array for the match
413
- if ( tempArr [ i ] + ' ' + $select . taggingLabel === needle ) {
414
- dupeIndex = i ;
415
- }
416
- // handle the object tagging implementation
417
- } else {
418
- var mockObj = tempArr [ i ] ;
419
- if ( angular . isObject ( mockObj ) ) {
420
- mockObj . isTag = true ;
421
- }
422
- if ( angular . equals ( mockObj , needle ) ) {
423
- dupeIndex = i ;
424
- }
425
- }
426
- }
427
- }
428
- return dupeIndex ;
429
- }
430
-
431
267
$select . searchInput . on ( 'blur' , function ( ) {
432
268
$timeout ( function ( ) {
433
269
$selectMultiple . activeMatchIndex = - 1 ;
0 commit comments