From 9368184aa88c3068e8e36edcd6a8935c9e07f189 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Mon, 1 May 2017 12:04:02 -0500 Subject: [PATCH] a11y: other-labels --- app/views/quiz/_checkbox_other.html.erb | 12 ++++++++---- app/views/quiz/_radio_other.html.erb | 13 +++++++++---- app/views/quiz/summary.html.erb | 1 + app/workers/candidate_quiz_question.rb | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/views/quiz/_checkbox_other.html.erb b/app/views/quiz/_checkbox_other.html.erb index fae8fd1..b9a938c 100644 --- a/app/views/quiz/_checkbox_other.html.erb +++ b/app/views/quiz/_checkbox_other.html.erb @@ -2,8 +2,8 @@ answers = question.answer.nil? ? [] : Array(question.answer['options']) other_value = question.answer.nil? ? '' : question.answer['other'] %> -
-
Select all that apply:
+
+
Select all that apply:
<% question.input_options.each do | option | option_id = "#{option.parameterize}_#{question.to_i}" @@ -20,12 +20,16 @@ <% option_id = "other_#{question.to_i}" checkbox_html = {class: "", id: option_id, data: { last: answers.include?('other') ? 'checked' : '' } } - text_html = {class: "", id: "text_#{option_id}", data: { last: other_value }} + text_html = {class: "", id: "value_#{option_id}", data: { last: other_value }} %> <%= check_box_tag('answer[answer_hash][options][]', 'other', answers.include?('other'), checkbox_html) %> <%= label_tag(option_id, 'Other') %> - <%= text_field_tag 'answer[answer_hash][other]', other_value, text_html.merge(id: "#{option_id}_value") %>
+
+ <%= label_tag text_html[:id], 'Other text' %> + <%= text_field_tag 'answer[answer_hash][other]', other_value, text_html %> +
+ <%= render partial: "quiz/answer_errors", locals: {question: question, answer: answer} %> diff --git a/app/views/quiz/_radio_other.html.erb b/app/views/quiz/_radio_other.html.erb index c5d0b3c..dc6c6d0 100644 --- a/app/views/quiz/_radio_other.html.erb +++ b/app/views/quiz/_radio_other.html.erb @@ -3,8 +3,8 @@ other_value = question.answer.nil? ? '' : question.answer['other'] %> -
-
Select the best option:
+
+
Select the best option:
<% question.input_options.each do | option | option_id = "#{option.parameterize}_#{question.to_i}" @@ -21,12 +21,17 @@ <% option_id = "other_#{question.to_i}" radio_html = {class: "", id: option_id, data: { last: answer_string }} - text_html = {class: "", id: "text_#{option_id}", data: { last: other_value }} + text_html = {class: "", id: "value_#{option_id}", data: { last: other_value }} %> <%= radio_button_tag('answer[answer_hash][options][]', 'other', (answer_string == 'other'), radio_html) %> <%= label_tag option_id, 'Other' %> - <%= text_field_tag 'answer[answer_hash][other]', other_value, text_html.merge(id: "value_#{option_id}") %> +
+
+ <%= label_tag text_html[:id], 'Other text' %> + <%= text_field_tag 'answer[answer_hash][other]', other_value, text_html %> +
+ <%= render partial: "quiz/answer_errors", locals: {question: question, answer: answer} %> diff --git a/app/views/quiz/summary.html.erb b/app/views/quiz/summary.html.erb index edd5d18..500e235 100644 --- a/app/views/quiz/summary.html.erb +++ b/app/views/quiz/summary.html.erb @@ -26,6 +26,7 @@ <% end %>
+ Review your answer <%= render partial: question.input_type, locals: {question: question, form: form, answer: question.answer} %>
diff --git a/app/workers/candidate_quiz_question.rb b/app/workers/candidate_quiz_question.rb index dad8a16..6890baa 100644 --- a/app/workers/candidate_quiz_question.rb +++ b/app/workers/candidate_quiz_question.rb @@ -13,11 +13,11 @@ class CandidateQuizQuestion def quiz_id row["quiz_id"] end - alias to_i quiz_id def question_id row["question_id"] end + alias to_i question_id def answer_id row["answer_id"]