Sha256: 2ad9b01fae1f4372c195e0ba05aedbb013b06a44f6c2a80a4ba94124d075e403

Contents?: true

Size: 1.12 KB

Versions: 25

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    # A form object to be used when public users want to create a proposal.
    class ProposalWizardCreateStepForm < Decidim::Form
      mimic :proposal

      attribute :title, String
      attribute :body, Decidim::Attributes::CleanString
      attribute :body_template, String
      attribute :user_group_id, Integer

      validates :title, :body, presence: true, etiquette: true
      validates :title, length: { in: 15..150 }
      validates :body, proposal_length: {
        minimum: 15,
        maximum: ->(record) { record.component.settings.proposal_length }
      }

      validate :body_is_not_bare_template

      alias component current_component

      def map_model(model)
        self.user_group_id = model.user_groups.first&.id
        return unless model.categorization

        self.category_id = model.categorization.decidim_category_id
      end

      private

      def body_is_not_bare_template
        return if body_template.blank?

        errors.add(:body, :cant_be_equal_to_template) if body.presence == body_template.presence
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-proposals-0.26.10 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.26.9 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.26.8 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.26.7 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.26.5 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.26.4 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.26.3 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.26.2 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.26.1 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.26.0 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.26.0.rc2 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.26.0.rc1 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.25.2 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.25.1 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.25.0 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.25.0.rc4 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.25.0.rc3 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.25.0.rc2 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.25.0.rc1 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.24.3 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb