Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added 'Add item link'

  • Loading branch information...
commit 23202f2cd439a31df9b76f7f418651950b29f3a5 1 parent a9cb635
@koenpunt authored
Showing with 14 additions and 1 deletion.
  1. +14 −1 coffee/chosen.jquery.coffee
View
15 coffee/chosen.jquery.coffee
@@ -401,11 +401,24 @@ class Chosen extends AbstractChosen
this.result_do_highlight do_high if do_high?
no_results: (terms) ->
- no_results_html = $('<li class="no-results">' + @results_none_found + ' "<span></span>"</li>')
+ no_results_html = $('<li class="no-results">' + @results_none_found + ' "<span></span>". <a href="javascript:void(0);" class="option-add">Add this item</a></li>')
no_results_html.find("span").first().html(terms)
+ no_results_html.find("a.option-add").bind "click", (evt) => this.select_add_option(terms)
@search_results.append no_results_html
+ select_add_option: (terms) ->
+ if $.isFunction(@options.addOption)
+ @options.addOption(terms);
+ else
+ new_option_html = $('<option />', {value: terms}).text(terms)
+ @form_field_jq.append new_option_html
+ @form_field_jq.trigger "liszt:updated"
+
+ @search_field.val terms
+ @search_field.trigger "keyup"
+ this.result_select()
+
no_results_clear: ->
@search_results.find(".no-results").remove()
Please sign in to comment.
Something went wrong with that request. Please try again.