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

Commit b3cae4f

Browse files
sudhirjIgorMinar
authored andcommitted
fix(select): select option with a label of 0 is not shown
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
1 parent 7b52a97 commit b3cae4f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/ng/directive/select.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
386386
selected,
387387
selectedSet = false, // nothing is selected yet
388388
lastElement,
389-
element;
389+
element,
390+
label;
390391

391392
if (multiple) {
392393
selectedSet = new HashMap(modelValue);
@@ -410,9 +411,11 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
410411
selected = modelValue === valueFn(scope, locals);
411412
selectedSet = selectedSet || selected; // see if at least one item is selected
412413
}
414+
label = displayFn(scope, locals); // what will be seen by the user
415+
label = label === undefined ? '' : label; // doing displayFn(scope, locals) || '' overwrites zero values
413416
optionGroup.push({
414417
id: keyName ? keys[index] : index, // either the index into array or key from object
415-
label: displayFn(scope, locals) || '', // what will be seen by the user
418+
label: label,
416419
selected: selected // determine if we should be selected
417420
});
418421
}

test/ng/directive/selectSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,21 @@ describe('select', function() {
493493
expect(sortedHtml(options[2])).toEqual('<option value="2">C</option>');
494494
});
495495

496+
it('should render zero as a valid display value', function() {
497+
createSingleSelect();
498+
499+
scope.$apply(function() {
500+
scope.values = [{name: 0}, {name: 1}, {name: 2}];
501+
scope.selected = scope.values[0];
502+
});
503+
504+
var options = element.find('option');
505+
expect(options.length).toEqual(3);
506+
expect(sortedHtml(options[0])).toEqual('<option value="0">0</option>');
507+
expect(sortedHtml(options[1])).toEqual('<option value="1">1</option>');
508+
expect(sortedHtml(options[2])).toEqual('<option value="2">2</option>');
509+
});
510+
496511

497512
it('should render an object', function() {
498513
createSelect({

0 commit comments

Comments
 (0)