Sha256: d75f105c1fb4527f13702dfbee4e60aeeff9398500adcecae038b0ad0dd47af8
Contents?: true
Size: 1.02 KB
Versions: 51
Compression:
Stored size: 1.02 KB
Contents
# frozen_string_literal: true module Decidim module Consultations # This form validates a MultiVote Question class MultiVoteForm < Form mimic :responses attribute :responses, Array[Integer] validate :valid_num_of_votes validate :valid_responses def vote_forms @vote_forms ||= responses.map do |response_id| VoteForm.from_params(decidim_consultations_response_id: response_id) end end private def valid_num_of_votes return if responses.count.between?(context.current_question.min_votes, context.current_question.max_votes) errors.add( :responses, I18n.t("activerecord.errors.models.decidim/consultations/vote.attributes.question.invalid_num_votes") ) end def valid_responses return if vote_forms.all?(&:valid?) errors.add( :responses, I18n.t("decidim_consultations_response_id.not_found", scope: "activemodel.errors.vote") ) end end end end
Version data entries
51 entries across 51 versions & 1 rubygems