Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(select): select option with a label of 0 is not shown
Browse files Browse the repository at this point in the history
Bug caused by the use of the `||` operator to replace all non-truthy
values with an empty string. Changed to replace only `undefined` values.

Closes #1401
  • Loading branch information
sudhirj authored and IgorMinar committed Oct 31, 2012
1 parent 537e200 commit d981c2a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ng/directive/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
selected,
selectedSet = false, // nothing is selected yet
lastElement,
element;
element,
label;

if (multiple) {
selectedSet = new HashMap(modelValue);
Expand All @@ -410,9 +411,11 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
selected = modelValue === valueFn(scope, locals);
selectedSet = selectedSet || selected; // see if at least one item is selected
}
label = displayFn(scope, locals); // what will be seen by the user
label = label === undefined ? '' : label; // doing displayFn(scope, locals) || '' overwrites zero values
optionGroup.push({
id: keyName ? keys[index] : index, // either the index into array or key from object
label: displayFn(scope, locals) || '', // what will be seen by the user
label: label,
selected: selected // determine if we should be selected
});
}
Expand Down
15 changes: 15 additions & 0 deletions test/ng/directive/selectSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,21 @@ describe('select', function() {
expect(sortedHtml(options[2])).toEqual('<option value="2">C</option>');
});

it('should render zero as a valid display value', function() {
createSingleSelect();

scope.$apply(function() {
scope.values = [{name: 0}, {name: 1}, {name: 2}];
scope.selected = scope.values[0];
});

var options = element.find('option');
expect(options.length).toEqual(3);
expect(sortedHtml(options[0])).toEqual('<option value="0">0</option>');
expect(sortedHtml(options[1])).toEqual('<option value="1">1</option>');
expect(sortedHtml(options[2])).toEqual('<option value="2">2</option>');
});


it('should render an object', function() {
createSelect({
Expand Down

0 comments on commit d981c2a

Please sign in to comment.