diff options
author | lou <louiscuny@gmail.com> | 2011-09-16 13:40:46 +0200 |
---|---|---|
committer | lou <louiscuny@gmail.com> | 2011-09-16 13:40:46 +0200 |
commit | e639f90c35b9a53f025e6a2bda8b079729eb42c3 (patch) | |
tree | 34dbca633fa9df88d6b73a12a518046c49444402 /js | |
parent | aa4b5d6ac1e611dfcf40531ceeede7cd9a87e5cf (diff) | |
download | multi-select-e639f90c35b9a53f025e6a2bda8b079729eb42c3.zip multi-select-e639f90c35b9a53f025e6a2bda8b079729eb42c3.tar.gz multi-select-e639f90c35b9a53f025e6a2bda8b079729eb42c3.tar.bz2 |
fix optgroup when label containing spaces
Diffstat (limited to 'js')
-rw-r--r-- | js/jquery.multi-select.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/js/jquery.multi-select.js b/js/jquery.multi-select.js index c5c9497..9fae41d 100644 --- a/js/jquery.multi-select.js +++ b/js/jquery.multi-select.js @@ -32,13 +32,17 @@ } ms.data('settings', multiSelects.settings); - var currentOptgroup = null; + var optgroupLabel = null, + optgroupId = null, + optgroupCpt = 0; ms.find('optgroup,option').each(function(){ if ($(this).is('optgroup')){ - currentOptgroup = $(this).attr('label'); - selectableUl.append($('<li class="ms-optgroup-container" id="ms-optgroup-'+ - $(this).attr('label')+'"><ul class="ms-optgroup"><li class="ms-optgroup-label">'+ - $(this).attr('label')+'</li></ul></li>')); + optgroupLabel = $(this).attr('label'); + optgroupId = 'ms-'+ms.attr('id')+'-optgroup-'+optgroupCpt; + selectableUl.append($('<li class="ms-optgroup-container" id="'+ + optgroupId+'"><ul class="ms-optgroup"><li class="ms-optgroup-label">'+ + optgroupLabel+'</li></ul></li>')); + optgroupCpt++; } if ($(this).is("option:not(option[value=''])")){ var selectableLi = $('<li class="ms-elem-selectable" ms-value="'+$(this).val()+'">'+$(this).text()+'</li>'); @@ -52,7 +56,7 @@ selectableLi.click(function(){ ms.multiSelect('select', $(this).attr('ms-value')); }); - var container = currentOptgroup ? selectableUl.children('#ms-optgroup-'+currentOptgroup).find('ul').first() : selectableUl; + var container = optgroupId ? selectableUl.children('#'+optgroupId).find('ul').first() : selectableUl; container.append(selectableLi); } }); |