Created
September 2, 2018 21:23
-
-
Save isubas/97b0ea0462570f1c1d1e0907201ade2b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<div class='form-group col-sm-6'> | |
<%= select_tag(:country_id, options_from_collection_for_select(Country.all, :id, :name), class: 'form-control') %> | |
</div> | |
<div class='form-group col-sm-6'> | |
<%= select_tag(:city_id, [], disabled: true, class: 'form-control') %> | |
</div> | |
<div class='form-group col-sm-6'> | |
<%= select_tag(:district_id, [], disabled: true, class: 'form-control') %> | |
</div> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
$('#country_id, #city_id, #district_id').select2(); | |
var parameters = [ | |
{ | |
el: '#country_id', // Zorunlu | |
target: '#city_id', // Zorunlu | |
params: { 'country_id': '#country_id' }, // source içerisinde parametre kullanılacaksa zorunlu | |
source: '/api/locations/countries/:country_id/cities/', // Zorunlu | |
value_attribute: 'id', // Opsiyonel, default: id | |
label_attribute: 'name', // Opsiyonel, default: name | |
reset_selectors: '#city_id, #district_id', // Opsiyonel | |
placeholder: 'Şehir Seçiniz' // Opsiyonel | |
}, | |
{ | |
el: '#city_id', | |
target: '#district_id', | |
params: { 'city_id': '#city_id' }, | |
source: '/api/locations/cities/:city_id/districts', | |
value_attribute: 'name', | |
reset_selectors: '#district_id', | |
placeholder: 'İlçe Seçiniz' | |
}, | |
] | |
var ajax_helper_for_selectbox = new ajaxHelper(parameters) | |
ajax_helper_for_selectbox.init() | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment