optgroup support #47

Closed
shalakolee opened this Issue Aug 11, 2016 · 1 comment

Projects

None yet

2 participants

shalakolee commented Aug 11, 2016 edited by FezVrasta

Hello,

I was using this with http://fezvrasta.github.io/bootstrap-material-design/#dropdown-menu, and happened to need optgroup support

i know this is just hacked together but mabye you could add this in....

REPLACE:

            $select.find("option").each(function() {
              // Cache $(this)
                var $this = $(this);
              methods._addOption($ul, $this);

WITH:

        var $hasOptGroups = $select.find("optgroup");
        if ($hasOptGroups.length > 0) {
            $hasOptGroups.each(function () {
                //add in the option group label
                var $optgroup = "<span class='optgroup'>" + $(this).attr("label") + "</span>";
                $ul.append($optgroup);
                //loop through the list and add each option
                $(this).find("option").each(function() {
                    // Cache $(this)
                    var $this = $(this);
                    methods._addOption($ul, $this);
                });
            });
        } else {
            // Loop trough options and transfer them to the dropdown menu
            $select.find("option").each(function() {
              // Cache $(this)
                var $this = $(this);
              methods._addOption($ul, $this);

            });            
        }

Thank You
Shalako Lee

Owner

I'm not actively maintaining this project anymore, feel free to submit a pull request if you want to see this feature inside Dropdown.js

@FezVrasta FezVrasta closed this Aug 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment