feat: hide pickup select on initial load when not applicable

This commit is contained in:
Björn Fromme
2025-01-16 14:54:46 +01:00
parent 9dc0992263
commit 6473ec8ec4
2 changed files with 16 additions and 13 deletions
@@ -4,18 +4,21 @@ export default class extends Controller {
static classes = [ 'hidden' ]
static targets = [ 'container' ]
static values = { show: Array }
static values = { show: Array, visible: Boolean }
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
this.visibleValue = this.showValue.indexOf(formValue) !== -1
} else {
let toggleValue = event.target.dataset.selectToggleValue
showContainer = true === event.target.checked && this.showValue.includes(toggleValue)
this.visibleValue = true === event.target.checked && this.showValue.includes(toggleValue)
}
this.containerTarget.classList.toggle(this.hiddenClass, false === showContainer)
}
visibleValueChanged(visible) {
this.containerTarget.classList.toggle(this.hiddenClass, false === visible)
}
}