autocomplete for zip and city

This commit is contained in:
2015-10-06 11:46:27 +02:00
parent d344b89d74
commit 790c482fae
9 changed files with 8614 additions and 1 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ html
= javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags
body
= console if Rails.env.development?
/ = console if Rails.env.development?
.container
= render 'shared/flashes'
= yield
+30
View File
@@ -9,3 +9,33 @@ h1 = title t('.title_html')
= f.input :support, as: :radio_buttons, collection: t('support_type'), label_method: :last, value_method: :first
= f.input :age_category, as: :radio_buttons, collection: t('age_category'), label_method: :last, value_method: :first
= f.submit value: t('.submit'), class: 'btn btn-success'
javascript:
var cities = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/cities_autocomplete.json?query=%QUERY',
wildcard: '%QUERY',
}
});
$('#supporter_city').typeahead({
minLength: 2,
highlight: true,
},{
display: 'city',
source: cities
}).on('typeahead:selected', function(event, datum) {
$("#supporter_zip").val(datum.plz);
});
$('#supporter_zip').typeahead({
minLength: 2,
highlight: true,
},{
display: 'plz',
source: cities
}).on('typeahead:selected', function(event, datum) {
$("#supporter_city").val(datum.city);
});