Newer
Older
dmpopidor / app / views / branded / questions / _new_edit_question_option_based.html.erb
<%# locals: { f, question, answer, research_output } %>
<% options = question.question_options.by_number %>
<% if question.question_format.checkbox? || question.question_format.multiselectbox? %>
    <%= f.label(:question_option_ids, sanitize(question.text), class: 'control-label') %>
    <% options.each do |op| %>
        <div class="checkbox">
            <label>
                <%= f.check_box(:question_option_ids, { multiple: true, checked: answer.has_question_option(op.id) || (answer.question_options.empty? && op.is_default?) }, op.id, nil) %>
                <%= sanitize op.text %>
            </label>
        </div>
    <% end %>
<% elsif question.question_format.radiobuttons? %>
    <%= f.label(:question_option_ids, sanitize(question.text), class: 'control-label') %>
    <% options.each do |op| %>
        <div class="radio">
            <label>
                <%= f.radio_button :question_option_ids, op.id, { checked: answer.has_question_option(op.id) || (answer.question_options.empty? && op.is_default?), id: "answer_option_ids_#{op.id}" } %>
                <%= sanitize op.text %>
            </label>
        </div>
    <% end %>
<% elsif question.question_format.dropdown? %>
    <%
        options_html = ""
        options.each do |op|
            options_html += answer.has_question_option(op.id) || (answer.question_options.empty? && op.is_default?) ?
                "<option value=#{op.id} selected=\"selected\">#{op.text}</option>" :
                "<option value=#{op.id}>#{op.text}</option>"
        end
    %>
    <%= f.label(:question_option_ids, sanitize(question.text), class: 'control-label') %>
    <%= select_tag('answer[question_option_ids]',
        options_html.html_safe,
        { multiple: question.question_format.multiselectbox?,
          prompt: d_('dmpopidor', 'Select an answer'),
          include_blank: question.question_format.dropdown?,
          class: 'form-control' }) %>
<% end %>
<div class="form-group">
<% if question.option_comment_display %><!-- Comment text area for option_based questions -->
    <% text = question.question_format.rda_metadata? ? answer.answer_hash['text'] : answer.text %>
    <%= label_tag('answer[text]', _('Additional Information'), class: 'control-label') %>
    <%= text_area_tag('answer[text]', text, id: "answer-text-#{question.id}-research-output-#{research_output.id}", class: "form-control tinymce_answer") %>
<% end %>
</div>