skill-assessment-app/app/views/quiz/_checkbox_other.html.erb

32 lines
1.3 KiB
Plaintext
Raw Normal View History

<%
answers = question.answer.nil? ? [] : Array(question.answer['options'])
other_value = question.answer.nil? ? '' : question.answer['other']
2017-04-18 17:15:38 -05:00
%>
<div role="group" aria-labelledby="<%= question.question_id %>">
<div id="<%= question.question_id %>">Select all that apply:</div>
2017-04-18 17:15:38 -05:00
<% question.input_options.each do | option |
option_id = "#{option.parameterize}_#{question.to_i}"
2017-03-20 10:57:50 -05:00
checkbox_html = {class: "", id: option_id, data: { last: answers.include?(option) ? 'checked' : '' } }
%>
2017-04-18 17:15:38 -05:00
<div>
2016-09-02 17:51:35 -05:00
<%= check_box_tag('answer[answer_hash][options][]', option, answers.include?(option), checkbox_html) %>
<%= label_tag(option_id, option) %>
</div>
<%
end %>
2017-04-18 17:15:38 -05:00
<div>
<%
option_id = "other_#{question.to_i}"
2017-03-20 10:57:50 -05:00
checkbox_html = {class: "", id: option_id, data: { last: answers.include?('other') ? 'checked' : '' } }
text_html = {class: "", id: "text_#{option_id}", data: { last: other_value }}
%>
2016-09-02 17:51:35 -05:00
<%= check_box_tag('answer[answer_hash][options][]', 'other', answers.include?('other'), checkbox_html) %>
<%= label_tag(option_id, 'Other') %>
2017-04-18 17:15:38 -05:00
<%= text_field_tag 'answer[answer_hash][other]', other_value, text_html.merge(id: "#{option_id}_value") %>
</div>
2017-04-18 17:15:38 -05:00
</div>
<%= render partial: "quiz/answer_errors", locals: {question: question, answer: answer} %>