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

multiselect items #99

Open
niralo1 opened this issue Aug 8, 2023 · 3 comments
Open

multiselect items #99

niralo1 opened this issue Aug 8, 2023 · 3 comments

Comments

@niralo1
Copy link

niralo1 commented Aug 8, 2023

Hi,

Does this plugin support multiselect items instead one by one?

@horkam
Copy link

horkam commented Aug 25, 2023

It does not appear to, although it would be nice. Another issue I'm having is that when you filter items then click on one to add, the items unfilter immediately and you have to go back to the filter box and type again to have it applied.

@ssada1975
Copy link

Solved modifying code like this:

_addButtonActions() {
this.add_all_button.addEventListener("click", t => this.actionAllSelected(t, this.availableList)), this.add_button.addEventListener("click", t => this.actionItemSelected(t)), this.remove_button.addEventListener("click", t => this.actionItemDeselected(t)), this.remove_all_button.addEventListener("click", t => this.actionAllDeselected(t, this.selectedList))
}

and then

actionAllSelected(t, l) {
let s = l.querySelectorAll(.${o}),
tp = {};
s.forEach((itm)=>{tp[itm.dataset.id]= itm.style.display});
t && t.preventDefault(), this.options.forEach(e => (e.selected = (!0 && tp[e.value]!="none"))), this.search_left.value="", this.redraw()
}
actionAllDeselected(t, l) {
let s = l.querySelectorAll(.${o}),
tp = {};
s.forEach((itm)=>{tp[itm.dataset.id]= itm.style.display});
t && t.preventDefault(), this.options.forEach(e => (e.selected = (!1 || tp[e.value]=="none"))), this.search_right.value="", this.redraw()
}``

@ssada1975
Copy link

additional to take into consideration ctrl key to select multiple lines

_actionItemClick(t, e, s = null) {
s && s.preventDefault();
let i = e.querySelectorAll(.${o});
for (let a = 0; a < i.length; a++) {
let l = i[a];
!s.ctrlKey && l !== t && l.classList.remove(n)
}
t.classList.contains(n) ? t.classList.remove(n) : t.classList.add(n)
}

and then

changeSelected(t) {
let ids = [];
ids = NodeList.prototype.isPrototypeOf(t) ? [...t].map(id => id.dataset.id) : Array.of(t.dataset.id);
this.options.forEach((e) => {
if (ids.includes(e.value)) {
e.selected = !e.selected, setTimeout(() => {
let s = document.createEvent("HTMLEvents");
e.selected ? (s.initEvent("added", !1, !0), s.addedElement = t) : (s.initEvent("removed", !1, !0), s.removedElement = t), this.dualListbox.dispatchEvent(s)
}, 0)
}
});
this.redraw();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants