From 369e610e9f54c0d23a5c62ae47b27cc194869fe9 Mon Sep 17 00:00:00 2001 From: andrew nimmo Date: Fri, 16 Aug 2024 00:29:07 -0700 Subject: [PATCH] hopefully fix checkboxes --- .../controllers/checkbox-collapse_controller.js | 13 +++++++------ .../controllers/observations/form/_details.html.erb | 2 +- .../observations/form/_specimen_section.html.erb | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/javascript/controllers/checkbox-collapse_controller.js b/app/javascript/controllers/checkbox-collapse_controller.js index d7152d5142..4ca368b53d 100644 --- a/app/javascript/controllers/checkbox-collapse_controller.js +++ b/app/javascript/controllers/checkbox-collapse_controller.js @@ -7,19 +7,19 @@ export default class extends Controller { connect() { this.element.dataset.stimulus = "checkbox-collapse-connected"; - this.checked = this.element.dataset.checked - if (this.hasFieldsTarget && this.checked) { - this.hideShowFields() + this.showPref = this.element.dataset.userPref + if (this.hasFieldsTarget && this.showPref) { + this.fieldsTarget.style.display = "none" + this.fieldsTarget.classList.remove("hidden") } } // Only show if user prefers hideShowFields() { if (this.checkboxTarget.checked) { - this.fieldsTarget.classList.remove("hidden") - this.hideFields() + $(this.fieldsTarget).show() } else { - this.showFields() + $(this.fieldsTarget).hide() } } @@ -31,6 +31,7 @@ export default class extends Controller { } showFields() { + this.fieldsTarget.classList.remove("hidden") $(this.fieldsTarget).show() this.checkCheckbox() } diff --git a/app/views/controllers/observations/form/_details.html.erb b/app/views/controllers/observations/form/_details.html.erb index ce09d35b6d..63a28e80eb 100644 --- a/app/views/controllers/observations/form/_details.html.erb +++ b/app/views/controllers/observations/form/_details.html.erb @@ -11,7 +11,7 @@ t_s = { %> <%= tag.div(class: "panel-body border-top", id: "observation_details", - data: { controller: "checkbox-collapse" }) do %> + data: { controller: "checkbox-collapse", user_pref: true }) do %> <%= tag.div(class: "row mt-3") do %> <%= tag.div(class: "col-xs-12 col-md-6") do %> diff --git a/app/views/controllers/observations/form/_specimen_section.html.erb b/app/views/controllers/observations/form/_specimen_section.html.erb index b8733b34f7..ea58eb8264 100644 --- a/app/views/controllers/observations/form/_specimen_section.html.erb +++ b/app/views/controllers/observations/form/_specimen_section.html.erb @@ -5,7 +5,7 @@ herbarium_record. Fields hidden unless box checked. %> <%= tag.div(id: "observation_specimen_section", data: { controller: "checkbox-collapse", - checked: (!@user.try(&:hide_specimen_stuff?)) }) do %> + user_pref: (!@user.try(&:hide_specimen_stuff?)) }) do %> <%= tag.div(class: "mt-3") do %> <%= check_box_with_label(