Form: add address auto complete

This commit is contained in:
Simon Lehericey 2017-07-26 12:09:21 +02:00 committed by Mathieu Magnin
parent 1a485f173e
commit 1b42766836
5 changed files with 46 additions and 1 deletions

View file

@ -18,4 +18,5 @@
//= require highcharts //= require highcharts
//= require chartkick //= require chartkick
//= require select2 //= require select2
//= require typeahead.bundle
//= require_tree . //= require_tree .

View file

@ -0,0 +1,27 @@
(function () {
var display = 'label';
var bloodhound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace(display),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/ban/search?request=%QUERY',
wildcard: '%QUERY'
}
});
bloodhound.initialize();
var bindTypeahead = function() {
$("input[data-address='true']").typeahead({
minLength: 1
}, {
display: display,
source: bloodhound,
limit: 5
});
};
document.addEventListener('turbolinks:load', bindTypeahead);
})();

View file

@ -12,7 +12,7 @@
display: inline-block; display: inline-block;
} }
input[type=text], input[type=text]:not([data-address='true']),
input[type=email], input[type=email],
input[type=password], input[type=password],
input[type=date], input[type=date],
@ -116,6 +116,21 @@
// scss-lint:enable // scss-lint:enable
} }
.twitter-typeahead {
margin-bottom: 2 * $default-padding;
}
input.tt-input,
input.tt-hint {
border-radius: 4px;
border: solid 1px $border-grey;
padding: $default-padding;
}
input.tt-hint {
color: $grey;
}
.datetime { .datetime {
input[type=date] { input[type=date] {
display: inline-block; display: inline-block;

View file

@ -5,4 +5,5 @@
// = require ./fonts // = require ./fonts
// = require leaflet.1.1.0 // = require leaflet.1.1.0
// = require select2 // = require select2
// = require typeahead
// = require_tree . // = require_tree .

View file

@ -1,6 +1,7 @@
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ } = render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { champ: champ }
%input{ type: 'text', %input{ type: 'text',
'data-address': 'true',
name: "champs['#{champ.id}']", name: "champs['#{champ.id}']",
id: "champs_#{champ.id}", id: "champs_#{champ.id}",
placeholder: champ.libelle, placeholder: champ.libelle,