Iron out quirks from navigating back and forth

This commit is contained in:
Jose Farias
2024-11-11 15:05:54 -06:00
parent eff8539b66
commit 9e99d961ba
3 changed files with 18 additions and 5 deletions
@@ -1,16 +1,27 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "button" ]
connect() {
this.buttonTargets.forEach(button => this.#showButton(button))
}
removeFilter(event) {
event.preventDefault()
this.#removeButton(event.target.closest("button"))
this.#hideButton(event.target.closest("button"))
}
clearCategory({ params: { name } }) {
this.element.querySelectorAll(`input[name="${name}"]`).forEach(input => this.#removeButton(input.closest("button")))
this.element.querySelectorAll(`input[name="${name}"]`).forEach(input => this.#hideButton(input.closest("button")))
}
#removeButton(button) {
#showButton(button) {
button.querySelector("input").disabled = false
button.hidden = false
}
#hideButton(button) {
button.querySelector("input").disabled = true
button.hidden = true
}