How to make optgroup selectable

1,683 views
Skip to first unread message

lmr...@gmail.com

unread,
Jul 13, 2015, 8:27:09 AM7/13/15
to sel...@googlegroups.com
Select 2 v4.0

Hi my json looks like:

data = [{
"id": "1",
"text": "group 1",
"children": [{
"id": "item1",
"text": "item1"
}, {
"id": "item2",
"text": "item2"
}]
}];

How can I make "group 1" selectable item? When item has childs I can't select it.

Kevin Brown

unread,
Jul 13, 2015, 1:27:11 PM7/13/15
to sel...@googlegroups.com
It's not possible in Select2, just like it's not possible in a standard `<select>` [1]. You can work around it though with custom templating functions and emulating groups [2][3].


--
You received this message because you are subscribed to the Google Groups "select2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.
To post to this group, send email to sel...@googlegroups.com.
Visit this group at http://groups.google.com/group/select2.
For more options, visit https://groups.google.com/d/optout.

b...@nestio.com

unread,
Aug 6, 2015, 4:25:33 PM8/6/15
to select2, lmr...@gmail.com
I just finished working on a plugin to make optgroups selectable:

https://github.com/bnjmnhndrsn/select2-optgroup-select

The behavior is slightly different from what you were describing. Optgroups don't have values themselves. Rather, clicking on an optgroup toggles/untoggles all of the child elements. However, it could be a good example for building what you want.

Reply all
Reply to author
Forward
0 new messages