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

If incorrectly use ng-attr-multiple, it turns the value into an array but not the select box #13570

Closed
hunterefox opened this issue Dec 17, 2015 · 3 comments

Comments

@hunterefox
Copy link

ng-attr-multiple is disabled, and if used correctly as in ng-attr-multiple="{{something}}", console correctly spits out a link to https://docs.angularjs.org/error/$compile/selmulti?p0=%3Cselect%20ng-model%3D%22model%22%20ng-required%3D%22mandatory%22%20ng-options%3D%22opt%20for%20opt%20in%20%5B%27One%27,%27Two%27%5D%22%20ng-attr-multiple%3D%22%7B%7Bfalse%7D%7D%22%3E

However, if use it incorrectly, e.g. ng-attr-multiple="something", it does not spit out an error, and instead while the select box renders as a single select, but the model is an array that never changes despite what is selected via the select box, e.g. it stays as "[]" despite selecting a different value from the select box. Validation/touched is called but not ng-change.

http://jsfiddle.net/wauv8n6y/1/

While this was my error for using ng-attr-multiple incorrectly, it should likely fail a bit better then it currently does.

@Narretz
Copy link
Contributor

Narretz commented Dec 19, 2015

This is expected, because when you are using ng-attr wrong, then the attribute isn't set at all. And because ng-attr is for binding arbitrary attributes, select does not "know" that ng-attr-multiple is trying to set the multiple attribute, it just reacts on multiple directly.

@hunterefox
Copy link
Author

Angular fails gracefully usually -- this doesn't really fail gracefully or provide any clues to what is wrong. Shouldn't there be some warning?

@Narretz
Copy link
Contributor

Narretz commented Dec 19, 2015

The only warning we could give, would be that ng-attr-multiple didn't receive an expression that could be evaluated on the scope. That is however incompatible with the fact that angular expression are by design forgiving (i.e. they don't throw if a "variable" isn't found). There have been requests to have a mode were something like your example will throw: #12120 You can give it an +1 but it's not high priority.

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

No branches or pull requests

2 participants