feat: hide pickup select on initial load when not applicable
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user