Permalink
Browse files

Merge branch 'elkelk-master'

  • Loading branch information...
meltingice committed Dec 15, 2012
2 parents 006324e + 8ffd452 commit f9b80a370777ce50c04e9680771e79ef0b2dab50
Showing with 18 additions and 11 deletions.
  1. +8 −4 lib/ajax-chosen.js
  2. +2 −1 lib/ajax-chosen.min.js
  3. +8 −6 src/ajax-chosen.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -78,14 +78,14 @@ do ($ = jQuery) ->
# ones that have not been selected by the user. For those selected
# by the user, add them to a list to filter from the results later.
selected_values = []
- select.find('optgroup').each ->
- $(@).remove()
-
select.find('option').each ->
if not $(@).is(":selected")
- $(@).remove()
+ $(@).remove()
else
selected_values.push $(@).val() + "-" + $(@).text()
+ select.find('optgroup:empty').each ->
+ $(@).remove()
+
# Send the ajax results to the user callback so we can get an object of
# value => text pairs to inject as <option> elements.
@@ -95,8 +95,10 @@ do ($ = jQuery) ->
# the DOM if it doesn't exist in the selector already
$.each items, (value, element) ->
if element.group
- group = $("<optgroup />")
- .attr('label', element.text)
+ group = select.find("optgroup[label='#{element.text}']")
+ group = $("<optgroup />") unless group.size()
+
+ group.attr('label', element.text)
.appendTo(select)
$.each element.items, (value, text) ->
if $.inArray(value + "-" + text, selected_values) == -1

0 comments on commit f9b80a3

Please sign in to comment.