Fix champ address on repetitions
This commit is contained in:
parent
a0a1ce11c8
commit
bb5c90c579
1 changed files with 22 additions and 7 deletions
|
@ -38,13 +38,28 @@ function source(url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
addEventListener('turbolinks:load', function() {
|
addEventListener('turbolinks:load', function() {
|
||||||
|
autocompleteSetup();
|
||||||
|
});
|
||||||
|
|
||||||
|
addEventListener('ajax:success', function() {
|
||||||
|
autocompleteSetup();
|
||||||
|
});
|
||||||
|
|
||||||
|
function autocompleteSetup() {
|
||||||
for (let { type, url } of sources) {
|
for (let { type, url } of sources) {
|
||||||
for (let target of document.querySelectorAll(selector(type))) {
|
for (let element of document.querySelectorAll(selector(type))) {
|
||||||
let select = autocomplete(target, options, [source(url)]);
|
if (!element.dataset.autocompleteInitialized) {
|
||||||
select.on('autocomplete:selected', ({ target }, suggestion) => {
|
autocompleteInitializeElement(element, url);
|
||||||
fire(target, 'autocomplete:select', suggestion);
|
}
|
||||||
select.autocomplete.setVal(suggestion.label);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
function autocompleteInitializeElement(element, url) {
|
||||||
|
const select = autocomplete(element, options, [source(url)]);
|
||||||
|
select.on('autocomplete:selected', ({ target }, suggestion) => {
|
||||||
|
fire(target, 'autocomplete:select', suggestion);
|
||||||
|
select.autocomplete.setVal(suggestion.label);
|
||||||
|
});
|
||||||
|
element.dataset.autocompleteInitialized = true;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue