Sha256: d09568a6b6a873237dbeb42d3909f35d441943983993a764d0c52ad7563ec574

Contents?: true

Size: 956 Bytes

Versions: 14

Compression:

Stored size: 956 Bytes

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, String
      attribute :user_group_id, Integer

      validates :title, :body, presence: true, etiquette: true
      validates :title, length: { maximum: 150 }

      validate :proposal_length

      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 proposal_length
        return unless body.presence
        length = current_component.settings.proposal_length
        errors.add(:body, :too_long, count: length) if body.length > length
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-proposals-0.18.1 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.17.2 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.18.0 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.17.1 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.16.1 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.17.0 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.16.0 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.15.2 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.15.1 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.15.0 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.14.4 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.14.3 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.14.2 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb
decidim-proposals-0.14.1 app/forms/decidim/proposals/proposal_wizard_create_step_form.rb