Make filters into a simple form

This commit is contained in:
Jose Farias
2024-11-14 21:50:38 -06:00
parent b6c4ba3b32
commit fb04249209
11 changed files with 63 additions and 120 deletions
@@ -1,27 +1,31 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "button" ]
static targets = [ "chip" ]
connect() {
this.buttonTargets.forEach(button => this.#showButton(button))
this.chipTargets.forEach(button => this.#showChip(button))
}
removeFilter(event) {
event.preventDefault()
this.#hideButton(event.target.closest("button"))
this.#hideChip(event.target.closest("button"))
}
clearCategory({ params: { name } }) {
this.element.querySelectorAll(`input[name="${name}"]`).forEach(input => this.#hideButton(input.closest("button")))
name.split(",").forEach(name => {
this.element.querySelectorAll(`input[name="${name}"]`).forEach(input => {
input.checked = false
})
})
}
#showButton(button) {
#showChip(button) {
button.querySelector("input").disabled = false
button.hidden = false
}
#hideButton(button) {
#hideChip(button) {
button.querySelector("input").disabled = true
button.hidden = true
}