Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue if an extension add an element between field and dropdownmenu #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Autocomplete {

insertAfter(dropdown, field);

this.dropdownEl = dropdown;
this.dropdown = new bootstrap.Dropdown(field, this.options.dropdownOptions);

field.addEventListener('click', (e) => {
Expand Down Expand Up @@ -99,7 +100,7 @@ class Autocomplete {
return 0;
}

const items = this.field.nextSibling;
const items = this.dropdownEl;
items.innerHTML = '';

const keys = Object.keys(this.options.data);
Expand All @@ -120,7 +121,7 @@ class Autocomplete {
}
}

this.field.nextSibling.querySelectorAll('.dropdown-item').forEach((item) => {
this.dropdownEl.querySelectorAll('.dropdown-item').forEach((item) => {
item.addEventListener('click', (e) => {
let dataLabel = e.currentTarget.getAttribute('data-label');
let dataValue = e.currentTarget.getAttribute('data-value');
Expand Down Expand Up @@ -171,4 +172,4 @@ function removeDiacritics(str) {
.replace(/[\u0300-\u036f]/g, '');
}

export { Autocomplete };
export { Autocomplete };