introduce check_other and radio_other question types
completes issue #48
This commit is contained in:
27
app/views/quiz/_checkbox_other.html.erb
Normal file
27
app/views/quiz/_checkbox_other.html.erb
Normal file
@ -0,0 +1,27 @@
|
||||
<%
|
||||
answers = question.answer.nil? ? [] : Array(question.answer['options'])
|
||||
other_value = question.answer.nil? ? '' : question.answer['other']
|
||||
|
||||
question.input_options.each do | option |
|
||||
option_id = "#{option.parameterize}_#{question.to_i}"
|
||||
checkbox_html = {class: 'checkbox', id: option_id, data: { last: answers.include?(option) ? 'checked' : '' } }
|
||||
%>
|
||||
<div class="form-group-multiples">
|
||||
<%= check_box_tag('answer[with_other][options][]', option, answers.include?(option), checkbox_html) %>
|
||||
<%= label_tag(option_id, option) %>
|
||||
</div>
|
||||
<%
|
||||
end %>
|
||||
|
||||
<div class="form-group-multiples">
|
||||
<%
|
||||
option_id = "other_#{question.to_i}"
|
||||
checkbox_html = {class: 'checkbox', id: option_id, data: { last: answers.include?('other') ? 'checked' : '' } }
|
||||
text_html = {class: 'input-other', id: "text_#{option_id}", data: { last: other_value }}
|
||||
%>
|
||||
<%= check_box_tag('answer[with_other][options][]', 'other', answers.include?('other'), checkbox_html) %>
|
||||
<%= label_tag(option_id, 'Other') %>
|
||||
<%= text_field_tag 'answer[with_other][other]', other_value, text_html %>
|
||||
</div>
|
||||
|
||||
<%= render partial: "quiz/answer_errors", locals: {question: question, answer: answer} %>
|
27
app/views/quiz/_radio_other.html.erb
Normal file
27
app/views/quiz/_radio_other.html.erb
Normal file
@ -0,0 +1,27 @@
|
||||
<%
|
||||
answer = question.answer.nil? ? '' : Array(question.answer['options']).first
|
||||
other_value = question.answer.nil? ? '' : question.answer['other']
|
||||
|
||||
question.input_options.each do | option |
|
||||
option_id = "#{option.parameterize}_#{question.to_i}"
|
||||
radio_html = {class: 'radio', id: option_id, data: {last: (answer == option) ? 'checked' : '' }}
|
||||
%>
|
||||
<div class="form-group-multiples">
|
||||
<%= radio_button_tag('answer[with_other][options][]', option, (answer == option), radio_html) %>
|
||||
<%= label_tag(option_id, option) %>
|
||||
</div>
|
||||
<%
|
||||
end %>
|
||||
|
||||
<div class="form-group-multiples">
|
||||
<%
|
||||
option_id = "other_#{question.to_i}"
|
||||
radio_html = {class: 'radio', id: option_id, data: { last: answer }}
|
||||
text_html = {class: 'input-other', id: "text_#{option_id}", data: { last: other_value }}
|
||||
%>
|
||||
<%= radio_button_tag('answer[with_other][options][]', 'other', (answer == 'other'), radio_html) %>
|
||||
<%= label_tag option_id, 'Other' %>
|
||||
<%= text_field_tag 'answer[with_other][other]', other_value, text_html %>
|
||||
</div>
|
||||
|
||||
<%= render partial: "quiz/answer_errors", locals: {question: question, answer: answer} %>
|
Reference in New Issue
Block a user