@@ -294,69 +294,74 @@ uis.controller('uiSelectCtrl',
294
294
295
295
// When the user selects an item with ENTER or clicks the dropdown
296
296
ctrl . select = function ( item , skipFocusser , $event ) {
297
- if ( item === undefined || ! item . _uiSelectChoiceDisabled ) {
298
-
299
- if ( ! ctrl . items && ! ctrl . search && ! ctrl . tagging . isActivated ) return ;
300
-
301
- if ( ! item || ! item . _uiSelectChoiceDisabled ) {
302
- if ( ctrl . tagging . isActivated ) {
303
- // if taggingLabel is disabled, we pull from ctrl.search val
304
- if ( ctrl . taggingLabel === false ) {
305
- if ( ctrl . activeIndex < 0 ) {
306
- item = ctrl . tagging . fct !== undefined ? ctrl . tagging . fct ( ctrl . search ) : ctrl . search ;
307
- if ( ! item || angular . equals ( ctrl . items [ 0 ] , item ) ) {
308
- return ;
309
- }
310
- } else {
311
- // keyboard nav happened first, user selected from dropdown
312
- item = ctrl . items [ ctrl . activeIndex ] ;
313
- }
314
- } else {
315
- // tagging always operates at index zero, taggingLabel === false pushes
316
- // the ctrl.search value without having it injected
317
- if ( ctrl . activeIndex === 0 ) {
318
- // ctrl.tagging pushes items to ctrl.items, so we only have empty val
319
- // for `item` if it is a detected duplicate
320
- if ( item === undefined ) return ;
321
-
322
- // create new item on the fly if we don't already have one;
323
- // use tagging function if we have one
324
- if ( ctrl . tagging . fct !== undefined && typeof item === 'string' ) {
325
- item = ctrl . tagging . fct ( ctrl . search ) ;
326
- if ( ! item ) return ;
327
- // if item type is 'string', apply the tagging label
328
- } else if ( typeof item === 'string' ) {
329
- // trim the trailing space
330
- item = item . replace ( ctrl . taggingLabel , '' ) . trim ( ) ;
331
- }
332
- }
333
- }
334
- // search ctrl.selected for dupes potentially caused by tagging and return early if found
335
- if ( ctrl . selected && angular . isArray ( ctrl . selected ) && ctrl . selected . filter ( function ( selection ) { return angular . equals ( selection , item ) ; } ) . length > 0 ) {
336
- ctrl . close ( skipFocusser ) ;
297
+ if ( item && item . _uiSelectChoiceDisabled === true )
298
+ return ;
299
+
300
+ if ( ! ctrl . items && ! ctrl . search && ! ctrl . tagging . isActivated )
301
+ return ;
302
+
303
+ if ( ctrl . tagging . isActivated ) {
304
+ //click is made on existing item, prevent from tagging, ctrl.search does not matter
305
+ var manualSelection = false ;
306
+ if ( $event && $event . type === 'click' && item ) {
307
+ manualSelection = true ;
308
+ }
309
+
310
+ // if taggingLabel is disabled, we pull from ctrl.search val
311
+ if ( ctrl . taggingLabel === false && manualSelection === false ) {
312
+ if ( ctrl . activeIndex < 0 ) {
313
+ item = ctrl . tagging . fct !== undefined ? ctrl . tagging . fct ( ctrl . search ) : ctrl . search ;
314
+ if ( ! item || angular . equals ( ctrl . items [ 0 ] , item ) ) {
337
315
return ;
338
316
}
317
+ } else {
318
+ // keyboard nav happened first, user selected from dropdown
319
+ item = ctrl . items [ ctrl . activeIndex ] ;
339
320
}
321
+ } else {
322
+ // tagging always operates at index zero, taggingLabel === false pushes
323
+ // the ctrl.search value without having it injected
324
+ if ( ctrl . activeIndex === 0 ) {
325
+ // ctrl.tagging pushes items to ctrl.items, so we only have empty val
326
+ // for `item` if it is a detected duplicate
327
+ if ( item === undefined ) return ;
328
+
329
+ // create new item on the fly if we don't already have one;
330
+ // use tagging function if we have one
331
+ if ( ctrl . tagging . fct !== undefined && typeof item === 'string' ) {
332
+ item = ctrl . tagging . fct ( ctrl . search ) ;
333
+ if ( ! item ) return ;
334
+ // if item type is 'string', apply the tagging label
335
+ } else if ( typeof item === 'string' ) {
336
+ // trim the trailing space
337
+ item = item . replace ( ctrl . taggingLabel , '' ) . trim ( ) ;
338
+ }
339
+ }
340
+ }
341
+ // search ctrl.selected for dupes potentially caused by tagging and return early if found
342
+ if ( ctrl . selected && angular . isArray ( ctrl . selected ) && ctrl . selected . filter ( function ( selection ) { return angular . equals ( selection , item ) ; } ) . length > 0 ) {
343
+ ctrl . close ( skipFocusser ) ;
344
+ return ;
345
+ }
346
+ }
340
347
341
- $scope . $broadcast ( 'uis:select' , item ) ;
348
+ $scope . $broadcast ( 'uis:select' , item ) ;
342
349
343
- var locals = { } ;
344
- locals [ ctrl . parserResult . itemName ] = item ;
350
+ var locals = { } ;
351
+ locals [ ctrl . parserResult . itemName ] = item ;
345
352
346
- $timeout ( function ( ) {
347
- ctrl . onSelectCallback ( $scope , {
348
- $item : item ,
349
- $model : ctrl . parserResult . modelMapper ( $scope , locals )
350
- } ) ;
351
- } ) ;
353
+ $timeout ( function ( ) {
354
+ ctrl . onSelectCallback ( $scope , {
355
+ $item : item ,
356
+ $model : ctrl . parserResult . modelMapper ( $scope , locals )
357
+ } ) ;
358
+ } ) ;
352
359
353
- if ( ctrl . closeOnSelect ) {
354
- ctrl . close ( skipFocusser ) ;
355
- }
356
- if ( $event && $event . type === 'click' ) {
357
- ctrl . clickTriggeredSelect = true ;
358
- }
359
- }
360
+ if ( ctrl . closeOnSelect ) {
361
+ ctrl . close ( skipFocusser ) ;
362
+ }
363
+ if ( $event && $event . type === 'click' ) {
364
+ ctrl . clickTriggeredSelect = true ;
360
365
}
361
366
} ;
362
367
0 commit comments