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

Commit 03c4827

Browse files
author
Brian Feister
committed
Fix case where undefined custom objects return isActive === true
1 parent 17a2e6e commit 03c4827

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) return;
273273
var data = ctrl.parserResult.source($scope);
@@ -305,7 +305,9 @@
305305
};
306306

307307
ctrl.isActive = function(itemScope) {
308-
return ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex;
308+
if ( typeof itemScope[ctrl.itemProperty] === 'undefined') {
309+
return false;
310+
}
309311
};
310312

311313
ctrl.isDisabled = function(itemScope) {
@@ -355,7 +357,7 @@
355357
_resetSearchInput();
356358
ctrl.open = false;
357359
$timeout(function(){
358-
ctrl.focusser[0].focus();
360+
ctrl.focusser[0].focus();
359361
},0,false);
360362
}
361363
};
@@ -425,7 +427,7 @@
425427
// Handles selected options in "multiple" mode
426428
function _handleMatchSelection(key){
427429
var caretPosition = _getCaretPosition(_searchInput[0]),
428-
length = ctrl.selected.length,
430+
length = ctrl.selected.length,
429431
// none = -1,
430432
first = 0,
431433
last = length-1,
@@ -448,7 +450,7 @@
448450
break;
449451
case KEY.RIGHT:
450452
// Open drop-down
451-
if(!~ctrl.activeMatchIndex || curr === last){
453+
if(!~ctrl.activeMatchIndex || curr === last){
452454
ctrl.activate();
453455
return false;
454456
}
@@ -471,7 +473,7 @@
471473
return curr;
472474
}
473475
else return false;
474-
}
476+
}
475477
}
476478

477479
newIndex = getNewActiveMatchIndex();
@@ -498,11 +500,11 @@
498500
if(ctrl.multiple && KEY.isHorizontalMovement(key)){
499501
processed = _handleMatchSelection(key);
500502
}
501-
503+
502504
if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) {
503505
processed = _handleDropDownSelection(key);
504506
}
505-
507+
506508
if (processed && key != KEY.TAB) {
507509
//TODO Check si el tab selecciona aun correctamente
508510
//Crear test
@@ -608,7 +610,7 @@
608610

609611
//From model --> view
610612
ngModel.$formatters.unshift(function (inputValue) {
611-
var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
613+
var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
612614
locals = {},
613615
result;
614616
if (data){
@@ -660,7 +662,7 @@
660662
if(attrs.tabindex){
661663
//tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex
662664
attrs.$observe('tabindex', function(value) {
663-
//If we are using multiple, add tabindex to the search input
665+
//If we are using multiple, add tabindex to the search input
664666
if($select.multiple){
665667
searchInput.attr("tabindex", value);
666668
} else {
@@ -715,7 +717,7 @@
715717
if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) {
716718
return;
717719
}
718-
720+
719721
$select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input
720722
focusser.val('');
721723
scope.$digest();
@@ -855,7 +857,7 @@
855857
if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression.");
856858

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

@@ -963,4 +965,4 @@ $templateCache.put("select2/select-multiple.tpl.html","<div class=\"ui-select-mu
963965
$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>");
964966
$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>");
965967
$templateCache.put("selectize/match.tpl.html","<div ng-hide=\"$select.searchEnabled && ($select.open || $select.isEmpty())\" class=\"ui-select-match\" ng-transclude=\"\"></div>");
966-
$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>");}]);
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>");}]);

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) return;
265265
var data = ctrl.parserResult.source($scope);
@@ -297,7 +297,9 @@
297297
};
298298

299299
ctrl.isActive = function(itemScope) {
300-
return ctrl.items.indexOf(itemScope[ctrl.itemProperty]) === ctrl.activeIndex;
300+
if ( typeof itemScope[ctrl.itemProperty] === 'undefined') {
301+
return false;
302+
}
301303
};
302304

303305
ctrl.isDisabled = function(itemScope) {
@@ -347,7 +349,7 @@
347349
_resetSearchInput();
348350
ctrl.open = false;
349351
$timeout(function(){
350-
ctrl.focusser[0].focus();
352+
ctrl.focusser[0].focus();
351353
},0,false);
352354
}
353355
};
@@ -417,7 +419,7 @@
417419
// Handles selected options in "multiple" mode
418420
function _handleMatchSelection(key){
419421
var caretPosition = _getCaretPosition(_searchInput[0]),
420-
length = ctrl.selected.length,
422+
length = ctrl.selected.length,
421423
// none = -1,
422424
first = 0,
423425
last = length-1,
@@ -440,7 +442,7 @@
440442
break;
441443
case KEY.RIGHT:
442444
// Open drop-down
443-
if(!~ctrl.activeMatchIndex || curr === last){
445+
if(!~ctrl.activeMatchIndex || curr === last){
444446
ctrl.activate();
445447
return false;
446448
}
@@ -463,7 +465,7 @@
463465
return curr;
464466
}
465467
else return false;
466-
}
468+
}
467469
}
468470

469471
newIndex = getNewActiveMatchIndex();
@@ -490,11 +492,11 @@
490492
if(ctrl.multiple && KEY.isHorizontalMovement(key)){
491493
processed = _handleMatchSelection(key);
492494
}
493-
495+
494496
if (!processed && (ctrl.items.length > 0 || ctrl.tagging.isActivated)) {
495497
processed = _handleDropDownSelection(key);
496498
}
497-
499+
498500
if (processed && key != KEY.TAB) {
499501
//TODO Check si el tab selecciona aun correctamente
500502
//Crear test
@@ -600,7 +602,7 @@
600602

601603
//From model --> view
602604
ngModel.$formatters.unshift(function (inputValue) {
603-
var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
605+
var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
604606
locals = {},
605607
result;
606608
if (data){
@@ -652,7 +654,7 @@
652654
if(attrs.tabindex){
653655
//tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex
654656
attrs.$observe('tabindex', function(value) {
655-
//If we are using multiple, add tabindex to the search input
657+
//If we are using multiple, add tabindex to the search input
656658
if($select.multiple){
657659
searchInput.attr("tabindex", value);
658660
} else {
@@ -707,7 +709,7 @@
707709
if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) {
708710
return;
709711
}
710-
712+
711713
$select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input
712714
focusser.val('');
713715
scope.$digest();
@@ -847,7 +849,7 @@
847849
if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression.");
848850

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

0 commit comments

Comments
 (0)