feat: multiselect field for filtering

This commit is contained in:
Björn Fromme
2024-07-15 18:25:14 +02:00
parent 1cb0227d1e
commit 7d84f321da
9 changed files with 151 additions and 31 deletions
@@ -0,0 +1,30 @@
import { Controller } from '@hotwired/stimulus'
export default class extends Controller {
static targets = [ 'label', 'dropdown', 'choice' ]
static values = { placeholder: String }
connect() {
this.update()
}
toggle() {
this.dropdownTarget.classList.toggle('hidden')
}
update() {
let labels = []
this.choiceTargets.forEach((choice) => {
if (choice.checked) {
labels.push(choice.dataset.label)
}
this.labelTarget.innerText = labels.join(', ')
})
if (0 === labels.length) {
this.labelTarget.innerText = this.placeholderValue
}
}
}