From bd7aa77e591133c09444cb3e1dfece895a948c8d Mon Sep 17 00:00:00 2001 From: arm1n Date: Mon, 10 Aug 2015 17:08:50 +0200 Subject: [PATCH] fix(ngOptions): allow empty option selection with multiple attribute fixes #12511 --- src/ng/directive/ngOptions.js | 2 +- test/ng/directive/ngOptionsSpec.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ng/directive/ngOptions.js b/src/ng/directive/ngOptions.js index 5f86dc4791ca..e07aa137f2a6 100644 --- a/src/ng/directive/ngOptions.js +++ b/src/ng/directive/ngOptions.js @@ -526,7 +526,7 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) { forEach(selectedValues, function(value) { var option = options.selectValueMap[value]; - if (!option.disabled) selections.push(options.getViewValueFromOption(option)); + if (option && !option.disabled) selections.push(options.getViewValueFromOption(option)); }); return selections; diff --git a/test/ng/directive/ngOptionsSpec.js b/test/ng/directive/ngOptionsSpec.js index 5498a61d9d12..bf6b7b720d9d 100644 --- a/test/ng/directive/ngOptionsSpec.js +++ b/test/ng/directive/ngOptionsSpec.js @@ -2058,6 +2058,18 @@ describe('ngOptions', function() { // ensure the option has not changed following the digest expect(element[0].selectedIndex).toEqual(0); }); + + // bug fix #12511 + it('should be selectable if multiple attribute is applied on select element',function() { + createMultiSelect(true); + + // select the empty option + setSelectValue(element,0); + + // ensure selection and correct binding + expect(element[0].selectedIndex).toEqual(0); + expect(scope.selected).toEqual([]); + }); });