Skip to content

Commit

Permalink
hopefully fix checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Aug 16, 2024
1 parent 959cdef commit 369e610
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions app/javascript/controllers/checkbox-collapse_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand All @@ -31,6 +31,7 @@ export default class extends Controller {
}

showFields() {
this.fieldsTarget.classList.remove("hidden")
$(this.fieldsTarget).show()
this.checkCheckbox()
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/controllers/observations/form/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ herbarium_record. Fields hidden unless box checked. %>

<%= tag.div(id: "observation_specimen_section",
data: { controller: "checkbox-collapse",
checked: ([email protected](&:hide_specimen_stuff?)) }) do %>
user_pref: ([email protected](&:hide_specimen_stuff?)) }) do %>

<%= tag.div(class: "mt-3") do %>
<%= check_box_with_label(
Expand Down

0 comments on commit 369e610

Please sign in to comment.