22 lines
756 B
JavaScript
22 lines
756 B
JavaScript
import { Controller } from '@hotwired/stimulus'
|
|
|
|
export default class extends Controller {
|
|
|
|
static classes = [ 'hidden' ]
|
|
static targets = [ 'container' ]
|
|
static values = { show: Array }
|
|
|
|
toggle(event) {
|
|
let fieldType = event.target.type
|
|
let formValue = event.target.value
|
|
let showContainer
|
|
if ('checkbox' !== fieldType && 'radio' !== fieldType) {
|
|
showContainer = this.showValue.indexOf(formValue) !== -1
|
|
} else {
|
|
let toggleValue = event.target.dataset.selectToggleValue
|
|
showContainer = true === event.target.checked && this.showValue.includes(toggleValue)
|
|
}
|
|
this.containerTarget.classList.toggle(this.hiddenClass, false === showContainer)
|
|
}
|
|
}
|