@@ -324,18 +324,44 @@ uis.controller('uiSelectCtrl',
324
324
ctrl . selected . filter ( function ( selection ) { return angular . equals ( selection , item ) ; } ) . length > 0 ) ;
325
325
} ;
326
326
327
+ var disabledItems = [ ] ;
328
+
329
+ function _updateItemDisabled ( item , isDisabled ) {
330
+ var disabledItemIndex = disabledItems . indexOf ( item ) ;
331
+ if ( isDisabled && disabledItemIndex === - 1 ) {
332
+ disabledItems . push ( item ) ;
333
+ }
334
+
335
+ if ( ! isDisabled && disabledItemIndex > - 1 ) {
336
+ disabledItems . splice ( disabledItemIndex , 0 ) ;
337
+ }
338
+ }
339
+
340
+ function _isItemDisabled ( item ) {
341
+ return disabledItems . indexOf ( item ) > - 1 ;
342
+ }
343
+
327
344
ctrl . isDisabled = function ( itemScope ) {
328
345
329
346
if ( ! ctrl . open ) return ;
330
347
331
- var itemIndex = ctrl . items . indexOf ( itemScope [ ctrl . itemProperty ] ) ;
348
+ var item = itemScope [ ctrl . itemProperty ] ;
349
+ var itemIndex = ctrl . items . indexOf ( item ) ;
332
350
var isDisabled = false ;
333
- var item ;
351
+
352
+ if ( itemIndex >= 0 && ( angular . isDefined ( ctrl . disableChoiceExpression ) || ctrl . multiple ) ) {
353
+
354
+ if ( item . isTag ) return false ;
355
+
356
+ if ( ctrl . multiple ) {
357
+ isDisabled = _isItemSelected ( item ) ;
358
+ }
334
359
335
- if ( itemIndex >= 0 && ( ! angular . isUndefined ( ctrl . disableChoiceExpression ) || ctrl . multiple ) ) {
336
- item = ctrl . items [ itemIndex ] ;
337
- isDisabled = ! ! ( itemScope . $eval ( ctrl . disableChoiceExpression ) ) || _isItemSelected ( item ) ; // force the boolean value
338
- item . _uiSelectChoiceDisabled = isDisabled ; // store this for later reference
360
+ if ( ! isDisabled && angular . isDefined ( ctrl . disableChoiceExpression ) ) {
361
+ isDisabled = ! ! ( itemScope . $eval ( ctrl . disableChoiceExpression ) ) ;
362
+ }
363
+
364
+ _updateItemDisabled ( item , isDisabled ) ;
339
365
}
340
366
341
367
return isDisabled ;
@@ -344,11 +370,11 @@ uis.controller('uiSelectCtrl',
344
370
345
371
// When the user selects an item with ENTER or clicks the dropdown
346
372
ctrl . select = function ( item , skipFocusser , $event ) {
347
- if ( item === undefined || ! item . _uiSelectChoiceDisabled ) {
373
+ if ( item === undefined || ! _isItemDisabled ( item ) ) {
348
374
349
375
if ( ! ctrl . items && ! ctrl . search && ! ctrl . tagging . isActivated ) return ;
350
376
351
- if ( ! item || ! item . _uiSelectChoiceDisabled ) {
377
+ if ( ! item || ! _isItemDisabled ( item ) ) {
352
378
if ( ctrl . tagging . isActivated ) {
353
379
// if taggingLabel is disabled and item is undefined we pull from ctrl.search
354
380
if ( ctrl . taggingLabel === false ) {
@@ -446,16 +472,53 @@ uis.controller('uiSelectCtrl',
446
472
}
447
473
} ;
448
474
449
- ctrl . isLocked = function ( itemScope , itemIndex ) {
450
- var isLocked , item = ctrl . selected [ itemIndex ] ;
475
+ // Set default function for locked choices - avoids unnecessary
476
+ // logic if functionality is not being used
477
+ ctrl . isLocked = function ( ) {
478
+ return false ;
479
+ } ;
480
+
481
+ $scope . $watch ( function ( ) {
482
+ return angular . isDefined ( ctrl . lockChoiceExpression ) && ctrl . lockChoiceExpression !== "" ;
483
+ } , _initaliseLockedChoices ) ;
451
484
452
- if ( item && ! angular . isUndefined ( ctrl . lockChoiceExpression ) ) {
453
- isLocked = ! ! ( itemScope . $eval ( ctrl . lockChoiceExpression ) ) ; // force the boolean value
454
- item . _uiSelectChoiceLocked = isLocked ; // store this for later reference
485
+ function _initaliseLockedChoices ( doInitalise ) {
486
+ if ( ! doInitalise ) return ;
487
+
488
+ var lockedItems = [ ] ;
489
+
490
+ function _updateItemLocked ( item , isLocked ) {
491
+ var lockedItemIndex = lockedItems . indexOf ( item ) ;
492
+ if ( isLocked && lockedItemIndex === - 1 ) {
493
+ lockedItems . push ( item ) ;
494
+ }
495
+
496
+ if ( ! isLocked && lockedItemIndex > - 1 ) {
497
+ lockedItems . splice ( lockedItemIndex , 0 ) ;
498
+ }
499
+ }
500
+
501
+ function _isItemlocked ( item ) {
502
+ return lockedItems . indexOf ( item ) > - 1 ;
503
+ }
504
+
505
+ ctrl . isLocked = function ( itemScope , itemIndex ) {
506
+ var isLocked = false ,
507
+ item = ctrl . selected [ itemIndex ] ;
508
+
509
+ if ( item ) {
510
+ if ( itemScope ) {
511
+ isLocked = ! ! ( itemScope . $eval ( ctrl . lockChoiceExpression ) ) ;
512
+ _updateItemLocked ( item , isLocked ) ;
513
+ } else {
514
+ isLocked = _isItemlocked ( item ) ;
515
+ }
455
516
}
456
517
457
518
return isLocked ;
458
- } ;
519
+ } ;
520
+ }
521
+
459
522
460
523
var sizeWatch = null ;
461
524
var updaterScheduled = false ;
0 commit comments