Skip to content

Commit

Permalink
fix(uiSelectSingleDirective): strictly compare matching value
Browse files Browse the repository at this point in the history
Use triple equals to determine if the selection matches
one of the choices.

Fixes angular-ui#1328
  • Loading branch information
fiznool authored and fcaballero committed Apr 25, 2016
1 parent 6d15343 commit ba37f13
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/uiSelectSingleDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp
var checkFnSingle = function(d){
locals[$select.parserResult.itemName] = d;
result = $select.parserResult.modelMapper(scope, locals);
return result == inputValue;
return result === inputValue;
};
//If possible pass same object stored in $select.selected
if ($select.selected && checkFnSingle($select.selected)) {
Expand Down Expand Up @@ -121,4 +121,4 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp

}
};
}]);
}]);
28 changes: 26 additions & 2 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ describe('ui-select tests', function() {
});

it('should correctly render initial state with track by $index', function () {

var el = compileTemplate(
'<ui-select ng-model="selection.selected"> \
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
Expand Down Expand Up @@ -776,6 +776,30 @@ describe('ui-select tests', function() {

});

it('should correctly render initial state (with object as source) differentiating between falsy values', function() {
scope.items = [{
label: '-- None Selected --',
value: ''
}, {
label: 'Yes',
value: true
}, {
label: 'No',
value: false
}];

var el = compileTemplate(
'<ui-select ng-model="selection.selected"> \
<ui-select-match>{{ $select.selected.label }}</ui-select-match> \
<ui-select-choices repeat="item.value as item in items track by item.value">{{ item.label }}</ui-select-choices> \
</ui-select>'
);

scope.selection.selected = '';
scope.$digest();
expect(getMatchLabel(el)).toEqual('-- None Selected --');
});

describe('disabled options', function() {
function createUiSelect(attrs) {
var attrsDisabled = '';
Expand Down Expand Up @@ -2322,7 +2346,7 @@ describe('ui-select tests', function() {

expect(el.scope().$select.multiple).toBe(true);
});

it('should preserve the model if tagging is enabled on select multiple', function() {
scope.selection.selectedMultiple = ["I am not on the list of choices"];

Expand Down

0 comments on commit ba37f13

Please sign in to comment.