From 6473ec8ec405ff1e7d541f71e00f92f91a8c383b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 16 Jan 2025 14:54:46 +0100 Subject: [PATCH] feat: hide pickup select on initial load when not applicable --- assets/controllers/select_toggle_controller.js | 11 +++++++---- templates/booking/edit.html.twig | 18 +++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/assets/controllers/select_toggle_controller.js b/assets/controllers/select_toggle_controller.js index 5ef3814..f306867 100644 --- a/assets/controllers/select_toggle_controller.js +++ b/assets/controllers/select_toggle_controller.js @@ -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) } } diff --git a/templates/booking/edit.html.twig b/templates/booking/edit.html.twig index 735539a..6f8f69e 100644 --- a/templates/booking/edit.html.twig +++ b/templates/booking/edit.html.twig @@ -130,7 +130,7 @@