mirror of
https://github.com/czhu12/canine.git
synced 2025-12-31 00:10:14 -06:00
21 lines
515 B
JavaScript
21 lines
515 B
JavaScript
import { Controller } from "@hotwired/stimulus"
|
|
|
|
export default class extends Controller {
|
|
static targets = ["select", "toggleable"]
|
|
static values = {
|
|
selectAttribute: String
|
|
}
|
|
|
|
connect() {
|
|
this.toggle()
|
|
}
|
|
|
|
toggle() {
|
|
const selectedValue = this.selectTarget.value
|
|
this.toggleableTargets.forEach(element => {
|
|
const shouldShow = element.getAttribute(this.selectTarget.dataset.selectAttributeValue) === selectedValue
|
|
element.classList.toggle('hidden', !shouldShow)
|
|
})
|
|
}
|
|
}
|