skill-assessment-app/app/views/quiz/_radio_other.html.erb
2017-06-05 11:30:35 -05:00

38 lines
1.3 KiB
Plaintext

<%
answer_string = question.answer.nil? ? '' : Array(question.answer['options']).first
other_value = question.answer.nil? ? '' : question.answer['other']
%>
<div role="group" aria-labelledby="<%= question.to_i %>">
<div id="<%= question.to_i %>">Select the best option:</div>
<% question.input_options.each do | option |
option_id = "#{option.parameterize}_#{question.to_i}"
radio_html = {class: "", id: option_id, data: {last: (answer_string == option) ? 'checked' : '' }}
%>
<div>
<%= radio_button_tag('answer[answer_hash][options][]', option, (answer_string == option), radio_html) %>
<%= label_tag(option_id, option) %>
</div>
<%
end %>
<div>
<%
option_id = "other_#{question.to_i}"
radio_html = {class: "", id: option_id, data: { last: answer_string }}
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' %>
</div>
</div>
<div>
<%= label_tag text_html[:id], 'Other text' %>
<%= text_field_tag 'answer[answer_hash][other]', other_value, text_html %>
</div>
<%= render partial: "quiz/answer_errors", locals: {question: question, answer: answer} %>