Permalink
Browse files

Guard against adding already selected options

  • Loading branch information...
1 parent 2fa4199 commit db74b39de783857066a21fe5001928402f310c0d @kamal kamal committed with Aug 5, 2011
Showing with 6 additions and 1 deletion.
  1. +6 −1 coffee/chosen.jquery.coffee
@@ -407,7 +407,12 @@ class Chosen extends AbstractChosen
no_results_html = $('<li class="no-results">' + @results_none_found + ' "<span></span>"</li>')
no_results_html.find("span").first().html(terms)
- no_results_html.find("a.option-add").bind "click", (evt) => this.select_add_option(terms)
+
+ regex = new RegExp('^' + terms + '$', 'i')
+ selected = (option for option in @results_data when regex.test(option.value) and option.selected)
+ if (selected.length == 0)
+ no_results_html.append(' <a href="javascript:void(0);" class="option-add">Add this item</a>')
+ no_results_html.find("a.option-add").bind "click", (evt) => this.select_add_option(terms)
@search_results.append no_results_html

0 comments on commit db74b39

Please sign in to comment.