Skip to content

Commit a574cd4

Browse files
committed
fix(uiSelectSingleDirective): strictly compare matching value
Use triple equals to determine if the selection matches one of the choices. Fixes angular-ui#1328
1 parent fe0c0c1 commit a574cd4

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

Diff for: src/uiSelectSingleDirective.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp
2525
var checkFnSingle = function(d){
2626
locals[$select.parserResult.itemName] = d;
2727
result = $select.parserResult.modelMapper(scope, locals);
28-
return result == inputValue;
28+
return result === inputValue;
2929
};
3030
//If possible pass same object stored in $select.selected
3131
if ($select.selected && checkFnSingle($select.selected)) {
@@ -121,4 +121,4 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp
121121

122122
}
123123
};
124-
}]);
124+
}]);

Diff for: test/select.spec.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ describe('ui-select tests', function() {
443443
});
444444

445445
it('should correctly render initial state with track by $index', function () {
446-
446+
447447
var el = compileTemplate(
448448
'<ui-select ng-model="selection.selected"> \
449449
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
@@ -776,6 +776,30 @@ describe('ui-select tests', function() {
776776

777777
});
778778

779+
it('should correctly render initial state (with object as source) differentiating between falsy values', function() {
780+
scope.items = [{
781+
label: '-- None Selected --',
782+
value: ''
783+
}, {
784+
label: 'Yes',
785+
value: true
786+
}, {
787+
label: 'No',
788+
value: false
789+
}];
790+
791+
var el = compileTemplate(
792+
'<ui-select ng-model="selection.selected"> \
793+
<ui-select-match>{{ $select.selected.label }}</ui-select-match> \
794+
<ui-select-choices repeat="item.value as item in items track by item.value">{{ item.label }}</ui-select-choices> \
795+
</ui-select>'
796+
);
797+
798+
scope.selection.selected = '';
799+
scope.$digest();
800+
expect(getMatchLabel(el)).toEqual('-- None Selected --');
801+
});
802+
779803
describe('disabled options', function() {
780804
function createUiSelect(attrs) {
781805
var attrsDisabled = '';
@@ -2310,7 +2334,7 @@ describe('ui-select tests', function() {
23102334

23112335
expect(el.scope().$select.multiple).toBe(true);
23122336
});
2313-
2337+
23142338
it('should preserve the model if tagging is enabled on select multiple', function() {
23152339
scope.selection.selectedMultiple = ["I am not on the list of choices"];
23162340

0 commit comments

Comments
 (0)