samedi 9 décembre 2017

Rails 4 - Validate that at least one checkboxe is checked in nested form inside a loop

I try to create a validation that work in a nested for with a collection of checkboxes.

The collection is inside a each.do loop.

<%= simple_form_for @questionnaire do |f| %>
    <% @questions.each do |question| %>
        <%= question.name %>
        <%= f.collection_check_boxes :answer_ids, Answer.where(question_id: question.id), :id, :content  %>
    <% end %>
<% end %>

This is inside a Questionnaire form.

So I try to validate answer in the Questionnaire model, but I need to do it for each question : each question should at least have a checkbox checked.

Any idea would be great! Thank you in advance!




Aucun commentaire:

Enregistrer un commentaire