Skip to content

Instantly share code, notes, and snippets.

@Iknewthisguy
Last active February 3, 2016 23:15
Show Gist options
  • Save Iknewthisguy/5549096 to your computer and use it in GitHub Desktop.
Save Iknewthisguy/5549096 to your computer and use it in GitHub Desktop.
nested_form and select2
= e.input :job_category_ids, :multiple => true, :input_html => { :class => "nested_chosen control-group", :id => "job_category_ids", :data => {:search_url => polymorphic_path([@parent, Offer], :action => 'job_category_search') } }, :label => 'Job categories'
$(document).on 'nested:fieldAdded', (event) ->
event.field.find('#job_category_ids').select2
width: "resolve"
ajax:
url: $('#job_category_ids').data('search-url')
dataType: "json"
data: (term, page) ->
values =
term: term
page: page
per: 10
results: (data, page) ->
results: data
multiple: true
initSelection: (element, callback) ->
data = []
$(element.val().split(",")).each ->
data.push
id: this
text: this
callback data
$('#job_category_ids').select2
width: "resolve"
ajax:
url: $('#job_category_ids').data('search-url')
dataType: "json"
data: (term, page) ->
values =
term: term
page: page
per: 10
results: (data, page) ->
results: data
multiple: true
initSelection: (element, callback) ->
data = []
$(element.val().split(",")).each ->
data.push
id: this
text: this
callback data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment