select with ng-multiple doesn't bind

1,976 views
Skip to first unread message

ni...@webpolis.com.ar

unread,
Dec 16, 2012, 2:58:42 PM12/16/12
to ang...@googlegroups.com
Hi 

I have the following select:

<select ng-model="selectedUsers" ng-options="u.value as u.name for u in users" ng-multiple="c.multipleUsers"></select>

But anytime i choose more than 1 option, it automatically resets the selection. It doesn't allow me to choose more than 1 option.

Any one has a clue?

Thank you 

Dave Merrill

unread,
Dec 16, 2012, 4:24:58 PM12/16/12
to ang...@googlegroups.com, ni...@webpolis.com.ar

ni...@webpolis.com.ar

unread,
Dec 18, 2012, 12:38:52 PM12/18/12
to ang...@googlegroups.com, ni...@webpolis.com.ar
Thank you, but it has nothing to do with my problem. I also know how to "google" for answers, and believe me, i arrived to the same site.

The problem is that the ng-multiple is bad implemented: if you bind an array to the "select", it won't select the values that are set in the array (if any).

Dave Merrill

unread,
Dec 18, 2012, 12:57:16 PM12/18/12
to ang...@googlegroups.com, ni...@webpolis.com.ar
My apologies, missed some of your detail, sorry it wasn't appropriate. 

(BTW, I didn't just google that; I'd run into it recently looking for something related, had commented there, thought it might help.)

Does the same problem happen if you use checkboxes instead of a multiple select? As I said in that question, I personally think that's a much better interface for expressing a set of options and a selection of them anyway. 

And please excuse if I'm once again suggesting suggesting something irrelevant.

Dave

ni...@webpolis.com.ar

unread,
Dec 18, 2012, 1:06:50 PM12/18/12
to ang...@googlegroups.com, ni...@webpolis.com.ar
I correct myself: the problem is ng-options in select....

So, let's say i have

showMultiple = 3;
selectedUsers = [{id:2},{id:4}];
users = [{id:1, name:'user1'}, {id: 2, name:'user2'},{id: 3, name:'user3'},{id: 4, name:'user4'}];

<select ng-multiple="showMultiple" ng-options="u.id as u.name for u in users" ng-model="selectedUsers" />

The "select" will render properly but the "selectdUsers" will not be chosen by default. So, basically, there is a bad implementation on the ng-options directive.

And yes, i can use checkboxes, but i thought angularjs was well polished and that i was misunderstanding the ng-options/select subject.

ni...@webpolis.com.ar

unread,
Dec 18, 2012, 1:07:39 PM12/18/12
to ang...@googlegroups.com, ni...@webpolis.com.ar
where it says: 

showMultiple = 3;

should say:

showMultiple = true;

Dave Merrill

unread,
Dec 18, 2012, 1:27:56 PM12/18/12
to ang...@googlegroups.com, ni...@webpolis.com.ar
I do see both problems you're reporting, that the no options are initially selected , and that you can't select more than one at a time, reverts to just one. Initial selection works if you just pass a simple value that's the same as an option value, but I couldn't figure out any way to get it to accept multiple values.

Of course that should be fixed (or someone could say what's misconfigured about it), but in the mean time, I really would use checkboxes instead. Multiple selects really aren't good for users, and if they also don't work well in Angular, that kind of settles it, at least for now.

Dave
Reply all
Reply to author
Forward
0 new messages