Merge pull request #3396 from betagouv/fix-data-autocomplete

autocomplete: fix initialization happening several times
This commit is contained in:
Paul Chavard 2019-02-07 15:34:52 +01:00 committed by GitHub
commit dea78e2e4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,9 +48,8 @@ addEventListener('ajax:success', function() {
function autocompleteSetup() {
for (let { type, url } of sources) {
for (let element of document.querySelectorAll(selector(type))) {
if (!element.dataset.autocompleteInitialized) {
autocompleteInitializeElement(element, url);
}
element.removeAttribute('data-autocomplete');
autocompleteInitializeElement(element, url);
}
}
}
@ -61,5 +60,4 @@ function autocompleteInitializeElement(element, url) {
fire(target, 'autocomplete:select', suggestion);
select.autocomplete.setVal(suggestion.label);
});
element.dataset.autocompleteInitialized = true;
}