From db96f77779af1c0ac5d2ea12781d0cab00d6a89d Mon Sep 17 00:00:00 2001 From: Siddique Hameed Date: Wed, 22 Jan 2014 14:05:29 -0600 Subject: [PATCH] fix(ngSelect): Support static options on multi-select drop down Removes a condition where static options are not added as part of render function when multiple attribute is enabled Closes #4325 --- src/ng/directive/select.js | 14 ++++++-------- test/ng/directive/selectSpec.js | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index e44b61e955cb..89f401e7822b 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -477,14 +477,12 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { selected: selected // determine if we should be selected }); } - if (!multiple) { - if (nullOption || modelValue === null) { - // insert null option if we have a placeholder, or the model is null - optionGroups[''].unshift({id:'', label:'', selected:!selectedSet}); - } else if (!selectedSet) { - // option could not be found, we have to insert the undefined item - optionGroups[''].unshift({id:'?', label:'', selected:true}); - } + if (nullOption || modelValue === null) { + // insert null option if we have a placeholder, or the model is null + optionGroups[''].unshift({id:'', label:'', selected:!selectedSet}); + } else if (!selectedSet) { + // option could not be found, we have to insert the undefined item + optionGroups[''].unshift({id:'?', label:'', selected:true}); } // Now we need to update the list of DOM nodes to match the optionGroups we computed above diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index 6fcd1fe05f82..f6d0fd8e6f39 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -1148,6 +1148,40 @@ describe('select', function() { }); + it('should include static option', function() { + createMultiSelect(''); + + scope.$apply(function() { + scope.values = [{name: 'A'}, {name: 'B'}]; + scope.selected = []; + }); + + expect(element.find('option').length).toEqual(3); + expect(element.find('option')[0].selected).toBeFalsy(); + expect(element.find('option')[1].selected).toBeFalsy(); + expect(element.find('option')[2].selected).toBeFalsy(); + + scope.$apply(function() { + scope.selected.push(scope.values[0]); + }); + + expect(element.find('option').length).toEqual(3); + + expect(element.find('option')[0].selected).toBeFalsy(); + expect(element.find('option')[1].selected).toBeTruthy(); + expect(element.find('option')[2].selected).toBeFalsy(); + + scope.$apply(function() { + scope.selected.push(scope.values[1]); + }); + + expect(element.find('option').length).toEqual(3); + expect(element.find('option')[0].selected).toBeFalsy(); + expect(element.find('option')[1].selected).toBeTruthy(); + expect(element.find('option')[2].selected).toBeTruthy(); + }); + + it('should update model on change', function() { createMultiSelect();