HemantNegi/jquery.sumoselect — pull request #14 by B2F (2014-10-23 09:48:14+00:00)
Title: Adding support for optgroups

Hello,

After trying Chosen and Sumoselect, I prefered the later for my user case (because of its ergonomy) and wanted to stick with it, but I needed support for groups and it wasn't an option...

So after a quick look at the source I was able to identify what to do (congratulation on the source readability!).

First, I replaced "children('option')" type of statement by the "find" equivalent so it can apply the magic to groups. It shouldn't change the behavior since the select can only have optgroup and option children. I haven't checked the performance, but if needed we could probably use children('option, optgroup > option') instead.

Second, I added a has_optgroups property to this.sumo and a addOptgroups method which insert groups labels as li, counting the number of preceding single options and groups options. The list stays flat.

To theme it I underlined groups labels and apply a padding-left 5px in any case standard or multi).

I tested the above code behavior with standard, multiselect and options between, before, after groups. It's also woking as intented without groups (as I know).

The only thing missing I'm aware of is the disabled support, but it won't be hard nor long to add if you ask me.

I also tried to respect the coding standards, let me know if anything else is missing for merging. This is an important feature in my opinion and I would be glad to be a part of the contributors.

Thanks for this awesome project !