diff --git a/app/helpers/question_attribute_helper.rb b/app/helpers/question_attribute_helper.rb index 04f0ad4bc..9a7335893 100644 --- a/app/helpers/question_attribute_helper.rb +++ b/app/helpers/question_attribute_helper.rb @@ -1,8 +1,7 @@ module QuestionAttributeHelper def stimulus_html_attributes(question) attribs = [ - numeric_question_html_attributes(question), - conditional_html_attributes(question), + numeric_question_html_attributes(question) ] merge_controller_attributes(*attribs) end @@ -20,16 +19,6 @@ private "data-calculated": question.fields_to_add.to_json, } end - - def conditional_html_attributes(question) - return {} if question.conditional_for.blank? - - { - "data-controller": "conditional-question", - "data-action": "conditional-question#displayConditional", - "data-info": question.conditional_for.to_json, - } - end end def merge_controller_attributes(*args) diff --git a/app/views/form/_radio_question.html.erb b/app/views/form/_radio_question.html.erb index d7f94a8e9..a079fc21c 100644 --- a/app/views/form/_radio_question.html.erb +++ b/app/views/form/_radio_question.html.erb @@ -9,7 +9,13 @@ <% if key.starts_with?("divider") %> <%= f.govuk_radio_divider %> <% else %> - <%= f.govuk_radio_button question.id, val, label: { text: val }, **stimulus_html_attributes(question) %> + <%= f.govuk_radio_button question.id, val, label: { text: val }, **stimulus_html_attributes(question) do %> + <% conditional_key = question.conditional_for&.find { |_, cval| cval.include? val }&.first %> + <% if conditional_key %> + <% conditional_question = @page.questions.find { |q| q.id == conditional_key } %> + <%= render partial: "#{conditional_question.type}_question", locals: { question: conditional_question, caption: caption, page_header: page_header, f: f } %> + <% end %> + <% end %> <% end %> <% end %> <% end %>