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

ngOptions.js throws type error when selecting empty value and using 'multiple' on select #12511

Closed
arm1n opened this issue Aug 6, 2015 · 1 comment

Comments

@arm1n
Copy link
Contributor

arm1n commented Aug 6, 2015

When selecting the empty value <option value=""></option> on a <select multiple="multiple" ng-options="v.label for(k,v) in options"> a type error is thrown.

OS/Browser: All
Version: Angular 1.4.3
Fiddle: https://jsfiddle.net/HB7LU/16138/
Code:

if (!option.disabled) selections.push(options.getViewValueFromOption(option));

Stack Trace:

TypeError: Cannot read property 'disabled' of undefined
    at angular.min.js:272
    at m (angular.min.js:7)
    at u.readValue (angular.min.js:272)
    at angular.min.js:285
    at n.$eval (angular.min.js:134)
    at n.$apply (angular.min.js:135)
    at HTMLSelectElement.<anonymous> (angular.min.js:285)
    at HTMLSelectElement.Gf.c (angular.min.js:35)

Fix:

Replace

if (!option.disabled) selections.push(options.getViewValueFromOption(option));

with

if (option && !option.disabled) selections.push(options.getViewValueFromOption(option));

same as in Line 517.

@lgalfaso
Copy link
Contributor

lgalfaso commented Aug 6, 2015

Looks like a real bug. PR welcome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants