Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit a692a48

Browse files
author
Brian Feister
committed
Fix case where undefined custom objects return isActive === true
1 parent 9ccfcc9 commit a692a48

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

dist/select.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
ctrl.selected = undefined;
159159
ctrl.open = false;
160160
ctrl.focus = false;
161-
ctrl.focusser = undefined; //Reference to input element used to handle focus events
161+
ctrl.focusser = undefined; //Reference to input element used to handle focus events
162162
ctrl.disabled = undefined; // Initialized inside uiSelect directive link function
163163
ctrl.searchEnabled = undefined; // Initialized inside uiSelect directive link function
164164
ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function
@@ -257,7 +257,7 @@
257257
var filteredItems = items.filter(function(i) {return ctrl.selected.indexOf(i) < 0;});
258258
setItemsFn(filteredItems);
259259
}else{
260-
setItemsFn(items);
260+
setItemsFn(items);
261261
}
262262
ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters
263263

@@ -267,7 +267,7 @@
267267
});
268268

269269
if (ctrl.multiple){
270-
//Remove already selected items
270+
//Remove already selected items
271271
$scope.$watchCollection('$select.selected', function(selectedItems){
272272
if (!selectedItems.length) return;
273273
var data = ctrl.parserResult.source($scope);
@@ -307,7 +307,9 @@
307307
};
308308

309309
ctrl.isActive = function(itemScope) {
310-
return ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex;
310+
if ( typeof itemScope[ctrl.itemProperty] === 'undefined') {
311+
return false;
312+
}
311313
};
312314

313315
ctrl.isDisabled = function(itemScope) {
@@ -357,7 +359,7 @@
357359
_resetSearchInput();
358360
ctrl.open = false;
359361
$timeout(function(){
360-
ctrl.focusser[0].focus();
362+
ctrl.focusser[0].focus();
361363
},0,false);
362364
}
363365
};
@@ -427,7 +429,7 @@
427429
// Handles selected options in "multiple" mode
428430
function _handleMatchSelection(key){
429431
var caretPosition = _getCaretPosition(_searchInput[0]),
430-
length = ctrl.selected.length,
432+
length = ctrl.selected.length,
431433
// none = -1,
432434
first = 0,
433435
last = length-1,
@@ -450,7 +452,7 @@
450452
break;
451453
case KEY.RIGHT:
452454
// Open drop-down
453-
if(!~ctrl.activeMatchIndex || curr === last){
455+
if(!~ctrl.activeMatchIndex || curr === last){
454456
ctrl.activate();
455457
return false;
456458
}
@@ -473,7 +475,7 @@
473475
return curr;
474476
}
475477
else return false;
476-
}
478+
}
477479
}
478480

479481
newIndex = getNewActiveMatchIndex();
@@ -500,11 +502,11 @@
500502
if(ctrl.multiple && KEY.isHorizontalMovement(key)){
501503
processed = _handleMatchSelection(key);
502504
}
503-
505+
504506
if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) {
505507
processed = _handleDropDownSelection(key);
506508
}
507-
509+
508510
if (processed && key != KEY.TAB) {
509511
//TODO Check si el tab selecciona aun correctamente
510512
//Crear test
@@ -612,7 +614,7 @@
612614

613615
//From model --> view
614616
ngModel.$formatters.unshift(function (inputValue) {
615-
var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
617+
var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
616618
locals = {},
617619
result;
618620
if (data){
@@ -664,7 +666,7 @@
664666
if(attrs.tabindex){
665667
//tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex
666668
attrs.$observe('tabindex', function(value) {
667-
//If we are using multiple, add tabindex to the search input
669+
//If we are using multiple, add tabindex to the search input
668670
if($select.multiple){
669671
searchInput.attr("tabindex", value);
670672
} else {
@@ -719,7 +721,7 @@
719721
if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) {
720722
return;
721723
}
722-
724+
723725
$select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input
724726
focusser.val('');
725727
scope.$digest();
@@ -857,7 +859,7 @@
857859
if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression.");
858860

859861
return function link(scope, element, attrs, $select, transcludeFn) {
860-
862+
861863
// var repeat = RepeatParser.parse(attrs.repeat);
862864
var groupByExp = attrs.groupBy;
863865

@@ -965,4 +967,4 @@ $templateCache.put("select2/select-multiple.tpl.html","<div class=\"ui-select-mu
965967
$templateCache.put("select2/select.tpl.html","<div class=\"select2 select2-container\" ng-class=\"{\'select2-container-active select2-dropdown-open\': $select.open,\n \'select2-container-disabled\': $select.disabled,\n \'select2-container-active\': $select.focus }\"><div class=\"ui-select-match\"></div><div class=\"select2-drop select2-with-searchbox select2-drop-active\" ng-class=\"{\'select2-display-none\': !$select.open}\"><div class=\"select2-search\" ng-show=\"$select.searchEnabled\"><input type=\"text\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" class=\"ui-select-search select2-input\" ng-model=\"$select.search\"></div><div class=\"ui-select-choices\"></div></div></div>");
966968
$templateCache.put("selectize/choices.tpl.html","<div ng-show=\"$select.open\" class=\"ui-select-choices selectize-dropdown single\"><div class=\"ui-select-choices-content selectize-dropdown-content\"><div class=\"ui-select-choices-group optgroup\"><div ng-show=\"$select.isGrouped\" class=\"ui-select-choices-group-label optgroup-header\">{{$group.name}}</div><div class=\"ui-select-choices-row\" ng-class=\"{active: $select.isActive(this), disabled: $select.isDisabled(this)}\"><div class=\"option ui-select-choices-row-inner\" data-selectable=\"\"></div></div></div></div></div>");
967969
$templateCache.put("selectize/match.tpl.html","<div ng-hide=\"$select.searchEnabled && ($select.open || $select.isEmpty())\" class=\"ui-select-match\" ng-transclude=\"\"></div>");
968-
$templateCache.put("selectize/select.tpl.html","<div class=\"selectize-control single\"><div class=\"selectize-input\" ng-class=\"{\'focus\': $select.open, \'disabled\': $select.disabled, \'selectize-focus\' : $select.focus}\" ng-click=\"$select.activate()\"><div class=\"ui-select-match\"></div><input type=\"text\" autocomplete=\"off\" tabindex=\"-1\" class=\"ui-select-search ui-select-toggle\" ng-click=\"$select.toggle($event)\" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-hide=\"!$select.searchEnabled || ($select.selected && !$select.open)\" ng-disabled=\"$select.disabled\"></div><div class=\"ui-select-choices\"></div></div>");}]);
970+
$templateCache.put("selectize/select.tpl.html","<div class=\"selectize-control single\"><div class=\"selectize-input\" ng-class=\"{\'focus\': $select.open, \'disabled\': $select.disabled, \'selectize-focus\' : $select.focus}\" ng-click=\"$select.activate()\"><div class=\"ui-select-match\"></div><input type=\"text\" autocomplete=\"off\" tabindex=\"-1\" class=\"ui-select-search ui-select-toggle\" ng-click=\"$select.toggle($event)\" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-hide=\"!$select.searchEnabled || ($select.selected && !$select.open)\" ng-disabled=\"$select.disabled\"></div><div class=\"ui-select-choices\"></div></div>");}]);

src/select.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
ctrl.selected = undefined;
151151
ctrl.open = false;
152152
ctrl.focus = false;
153-
ctrl.focusser = undefined; //Reference to input element used to handle focus events
153+
ctrl.focusser = undefined; //Reference to input element used to handle focus events
154154
ctrl.disabled = undefined; // Initialized inside uiSelect directive link function
155155
ctrl.searchEnabled = undefined; // Initialized inside uiSelect directive link function
156156
ctrl.resetSearchInput = undefined; // Initialized inside uiSelect directive link function
@@ -249,7 +249,7 @@
249249
var filteredItems = items.filter(function(i) {return ctrl.selected.indexOf(i) < 0;});
250250
setItemsFn(filteredItems);
251251
}else{
252-
setItemsFn(items);
252+
setItemsFn(items);
253253
}
254254
ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters
255255

@@ -259,7 +259,7 @@
259259
});
260260

261261
if (ctrl.multiple){
262-
//Remove already selected items
262+
//Remove already selected items
263263
$scope.$watchCollection('$select.selected', function(selectedItems){
264264
if (!selectedItems.length) return;
265265
var data = ctrl.parserResult.source($scope);
@@ -299,7 +299,9 @@
299299
};
300300

301301
ctrl.isActive = function(itemScope) {
302-
return ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex;
302+
if ( typeof itemScope[ctrl.itemProperty] === 'undefined') {
303+
return false;
304+
}
303305
};
304306

305307
ctrl.isDisabled = function(itemScope) {
@@ -349,7 +351,7 @@
349351
_resetSearchInput();
350352
ctrl.open = false;
351353
$timeout(function(){
352-
ctrl.focusser[0].focus();
354+
ctrl.focusser[0].focus();
353355
},0,false);
354356
}
355357
};
@@ -419,7 +421,7 @@
419421
// Handles selected options in "multiple" mode
420422
function _handleMatchSelection(key){
421423
var caretPosition = _getCaretPosition(_searchInput[0]),
422-
length = ctrl.selected.length,
424+
length = ctrl.selected.length,
423425
// none = -1,
424426
first = 0,
425427
last = length-1,
@@ -442,7 +444,7 @@
442444
break;
443445
case KEY.RIGHT:
444446
// Open drop-down
445-
if(!~ctrl.activeMatchIndex || curr === last){
447+
if(!~ctrl.activeMatchIndex || curr === last){
446448
ctrl.activate();
447449
return false;
448450
}
@@ -465,7 +467,7 @@
465467
return curr;
466468
}
467469
else return false;
468-
}
470+
}
469471
}
470472

471473
newIndex = getNewActiveMatchIndex();
@@ -492,11 +494,11 @@
492494
if(ctrl.multiple && KEY.isHorizontalMovement(key)){
493495
processed = _handleMatchSelection(key);
494496
}
495-
497+
496498
if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) {
497499
processed = _handleDropDownSelection(key);
498500
}
499-
501+
500502
if (processed && key != KEY.TAB) {
501503
//TODO Check si el tab selecciona aun correctamente
502504
//Crear test
@@ -604,7 +606,7 @@
604606

605607
//From model --> view
606608
ngModel.$formatters.unshift(function (inputValue) {
607-
var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
609+
var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
608610
locals = {},
609611
result;
610612
if (data){
@@ -656,7 +658,7 @@
656658
if(attrs.tabindex){
657659
//tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex
658660
attrs.$observe('tabindex', function(value) {
659-
//If we are using multiple, add tabindex to the search input
661+
//If we are using multiple, add tabindex to the search input
660662
if($select.multiple){
661663
searchInput.attr("tabindex", value);
662664
} else {
@@ -711,7 +713,7 @@
711713
if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) {
712714
return;
713715
}
714-
716+
715717
$select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input
716718
focusser.val('');
717719
scope.$digest();
@@ -849,7 +851,7 @@
849851
if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression.");
850852

851853
return function link(scope, element, attrs, $select, transcludeFn) {
852-
854+
853855
// var repeat = RepeatParser.parse(attrs.repeat);
854856
var groupByExp = attrs.groupBy;
855857

0 commit comments

Comments
 (0)