Skip to content

Commit

Permalink
prevent issue for multiple inits
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Dec 23, 2021
1 parent 117ec91 commit abff7f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<script type="module">
import Tags from "./tags.js";
Tags.init("select[multiple]:not(#regular)");
// Multiple inits should not matter
Tags.init("select[multiple]:not(#regular)");

// Reset does not fire a change input
document.getElementById("regular").addEventListener("change", function (ev) {
Expand Down
7 changes: 5 additions & 2 deletions tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Tags {
constructor(selectElement, opts = {}) {
this.selectElement = selectElement;
this.selectElement.style.display = "none";
this.selectElement.dataset.tags = true;

this.placeholder = this.getPlaceholder();
this.allowNew = selectElement.dataset.allowNew ? true : false;
this.showAllSuggestions = selectElement.dataset.showAllSuggestions ? true : false;
Expand Down Expand Up @@ -88,8 +90,9 @@ class Tags {
static init(selector = "select[multiple]", opts = {}) {
let list = document.querySelectorAll(selector);
for (let i = 0; i < list.length; i++) {
let el = list[i];
let inst = new Tags(el, opts);
if (!list[i].dataset.tags) {
new Tags(list[i], opts);
}
}
}

Expand Down

0 comments on commit abff7f0

Please sign in to comment.