Sha256: 71c37cb8c3d3b2b7a14acfe930d47c73a7e3043dea592bcea076af5a76038a65

Contents?: true

Size: 614 Bytes

Versions: 4

Compression:

Stored size: 614 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module ActionDelegator
    module Admin
      class PonderationForm < Form
        mimic :ponderation

        attribute :weight, Decimal, default: 1.0
        attribute :name, String

        validates :weight, :name, presence: true
        validate :name_uniqueness

        def name_uniqueness
          return unless setting
          return unless setting.ponderations.where(name: name).where.not(id: id).any?

          errors.add(:name, :taken)
        end

        def setting
          @setting ||= context[:setting]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decidim-action_delegator-0.8.1 app/forms/decidim/action_delegator/admin/ponderation_form.rb
decidim-action_delegator-0.7.2 app/forms/decidim/action_delegator/admin/ponderation_form.rb
decidim-action_delegator-0.7.1 app/forms/decidim/action_delegator/admin/ponderation_form.rb
decidim-action_delegator-0.7.0 app/forms/decidim/action_delegator/admin/ponderation_form.rb