Permalink
Browse files

Updated the way for adding items using a custom callback

removed debug console.log
  • Loading branch information...
1 parent ab38e05 commit 7d652180dfe5f500488c478e356eeb2d7dcda885 @koenpunt committed Dec 19, 2011

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -417,7 +417,7 @@ class Chosen extends AbstractChosen
select_create_option: (terms) ->
if $.isFunction(@create_option)
- @create_option.call this, terms, this.select_append_option
+ @create_option.call this, terms
else
this.select_append_option( {value: terms, text: terms} )
View
@@ -12,7 +12,7 @@ class @Chosen extends AbstractChosen
@multi_temp = new Template('<ul class="chosen-choices"><li class="search-field"><input type="text" value="#{default}" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>')
@no_results_temp = new Template('<li class="no-results">' + @results_none_found + ' "<span>#{terms}</span>".#{add_item_link}</li>')
@new_option_temp = new Template('<option value="#{value}">#{text}</option>')
- @add_link_temp = new Template(' <a href="javascript:void(0);" class="option-add">' + @add_option_text + '</a>')
+ @add_link_temp = new Template(' <a href="javascript:void(0);" class="option-add">' + @create_option_text + '</a>')
set_up_html: ->
container_classes = ["chosen-container"]
@@ -408,21 +408,17 @@ class @Chosen extends AbstractChosen
@search_results.insert @no_results_temp.evaluate( terms: terms, add_item_link: add_item_link )
- if @options.addOption and not selected
- @search_results.down("a.option-add").observe "click", (evt) => this.select_add_option(terms) unless selected
-
- select_add_option: ( terms ) ->
- if Object.isFunction(@add_option)
- @add_option.call this, terms, this.select_append_option
+ select_create_option: ( terms ) ->
+ if Object.isFunction( @create_option )
+ @create_option.call this, terms
else
this.select_append_option {value: terms, text: terms}
select_append_option: ( options ) ->
###
TODO Close options after adding
###
-
- option = @new_option_temp.evaluate( value: options.value, text: options.text )
+ option = @new_option_temp.evaluate( options )
@form_field.insert option
Event.fire @form_field, "liszt:updated"
this.result_select()
@@ -104,6 +104,9 @@ class AbstractChosen
this.outerHTML(group_el)
+ append_option: (option) ->
+ this.select_append_option(option)
+
results_update_field: ->
this.set_default_text()
this.results_reset_cleanup() if not @is_multiple

0 comments on commit 7d65218

Please sign in to comment.