Last active
February 3, 2016 23:15
-
-
Save Iknewthisguy/5549096 to your computer and use it in GitHub Desktop.
nested_form and select2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= 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