Browse Source

display checkbox answers

pull/79/head
Kat 4 years ago
parent
commit
07a63d8e41
  1. 17
      app/models/form.rb
  2. 2
      app/views/form/_check_answers_table.html.erb
  3. 2
      app/views/form/check_answers.html.erb

17
app/models/form.rb

@ -90,4 +90,21 @@ class Form
pages_for_subsection(subsection).keys[current_page_idx - 1]
end
def all_questions
@all_questions ||= all_pages.map { |_page_key, page_value|
page_value["questions"]
}.reduce(:merge)
end
def get_answer_label(case_log, question_title)
question = all_questions[question_title]
if question["type"] == "checkbox"
answer = []
question["answer_options"].each { |key, value| case_log[key] == "Yes" ? answer << value : nil }
return answer.join(", ")
end
case_log[question_title]
end
end

2
app/views/form/_check_answers_table.html.erb

@ -4,7 +4,7 @@
<%= question_info["check_answer_label"].to_s.present? ? question_info["check_answer_label"].to_s : question_info["header"].to_s%>
<dt>
<dd class="govuk-summary-list__value">
<%= @case_log[question_title] %>
<%= form.get_answer_label(@case_log, question_title) %>
</dd>
<dd class="govuk-summary-list__actions">
<%= create_update_answer_link(@case_log[question_title], @case_log.id, page)%>

2
app/views/form/check_answers.html.erb

@ -6,7 +6,7 @@
<% form.pages_for_subsection(subsection).each do |page, page_info| %>
<% page_info["questions"].each do |question_title, question_info| %>
<% if total_questions(subsection, @case_log, form).include?(question_title) %>
<%= render partial: 'form/check_answers_table', locals: { question_title: question_title, question_info: question_info, case_log: @case_log, page: page } %>
<%= render partial: 'form/check_answers_table', locals: { question_title: question_title, question_info: question_info, case_log: @case_log, page: page, form: form } %>
<%end %>
<%end %>
<% end %>

Loading…
Cancel
Save