Sha256: dc931ed2713591c7f46ba22b925fa40d80b1972cfa9bd1d100270cb89d6fa769

Contents?: true

Size: 1.35 KB

Versions: 38

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    module Admin
      # This class holds a Form to update questionnaire questions from Decidim's admin panel.
      class QuestionForm < Decidim::Form
        include TranslatableAttributes

        attribute :position, Integer
        attribute :mandatory, Boolean, default: false
        attribute :question_type, String
        attribute :answer_options, Array[AnswerOptionForm]
        attribute :max_choices, Integer
        attribute :deleted, Boolean, default: false

        translatable_attribute :body, String
        translatable_attribute :description, String

        validates :position, numericality: { greater_than_or_equal_to: 0 }
        validates :question_type, inclusion: { in: Decidim::Meetings::Question::QUESTION_TYPES }
        validates :max_choices, numericality: { only_integer: true, greater_than: 1, less_than_or_equal_to: ->(form) { form.number_of_options } }, allow_blank: true
        validates :body, translatable_presence: true, if: :requires_body?
        validates :answer_options, presence: true

        def to_param
          return id if id.present?

          "questionnaire-question-id"
        end

        def number_of_options
          answer_options.size
        end

        private

        def requires_body?
          !deleted
        end
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
decidim-meetings-0.28.4 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.27.9 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.28.3 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.27.8 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.28.2 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.27.7 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.28.1 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.27.6 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.26.10 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.26.9 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.28.0 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.27.5 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.28.0.rc5 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.28.0.rc4 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.26.8 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.27.4 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.27.3 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.26.7 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.26.5 app/forms/decidim/meetings/admin/question_form.rb
decidim-meetings-0.27.2 app/forms/decidim/meetings/admin/question_form.rb