Browse Source

Make controller naming more explicit

pull/29/head
baarkerlounger 4 years ago
parent
commit
a488e79bc4
  1. 17
      app/javascript/controllers/conditional_question_controller.js
  2. 4
      app/views/form/_radio_question.html.erb

17
app/javascript/controllers/conditional_question_controller.js

@ -0,0 +1,17 @@
import { Controller } from "stimulus"
export default class extends Controller {
displayConditional() {
let question = this.element.name;
let selected = this.element.value;
let conditional_for = JSON.parse(this.element.dataset.info);
Object.entries(conditional_for).forEach(([key, values]) => {
if(values.includes(selected)) {
document.getElementById(key + "_div").style.display = "block"
} else {
document.getElementById(key + "_div").style.display = "none"
}
});
}
}

4
app/views/form/_radio_question.html.erb

@ -8,8 +8,8 @@
<%= f.govuk_radio_divider %>
<% elsif question["conditional_for"] %>
<%= f.govuk_radio_button question_key, key, label: { text: val },
"data-controller": "conditional",
"data-action": "click->conditional#displayConditional",
"data-controller": "conditional-question",
"data-action": "click->conditional-question#displayConditional",
"data-info": "#{question["conditional_for"].to_json}"
%>
<% else %>

Loading…
Cancel
Save