Sha256: a64b28871fa18bf76541dcf6ff85da508ad4881404232d67e277842c8b1d7e08

Contents?: true

Size: 832 Bytes

Versions: 74

Compression:

Stored size: 832 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A form object to create or update areas.
    class AreaForm < Form
      include TranslatableAttributes

      translatable_attribute :name, String
      attribute :organization, Decidim::Organization
      attribute :area_type_id, Integer

      mimic :area

      validates :name, translatable_presence: true
      validates :organization, presence: true

      validate :name_uniqueness

      def name_uniqueness
        return unless organization
        return unless organization.areas.where(name: name, area_type: area_type).where.not(id: id).any?

        errors.add(:name, :taken)
      end

      alias organization current_organization

      def area_type
        Decidim::AreaType.find_by(id: area_type_id) if area_type_id
      end
    end
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
decidim-admin-0.27.9 app/forms/decidim/admin/area_form.rb
decidim-admin-0.27.8 app/forms/decidim/admin/area_form.rb
decidim-admin-0.27.7 app/forms/decidim/admin/area_form.rb
decidim-admin-0.27.6 app/forms/decidim/admin/area_form.rb
decidim-admin-0.26.10 app/forms/decidim/admin/area_form.rb
decidim-admin-0.26.9 app/forms/decidim/admin/area_form.rb
decidim-admin-0.27.5 app/forms/decidim/admin/area_form.rb
decidim-admin-0.26.8 app/forms/decidim/admin/area_form.rb
decidim-admin-0.27.4 app/forms/decidim/admin/area_form.rb
decidim-admin-0.27.3 app/forms/decidim/admin/area_form.rb
decidim-admin-0.26.7 app/forms/decidim/admin/area_form.rb
decidim-admin-0.26.5 app/forms/decidim/admin/area_form.rb
decidim-admin-0.27.2 app/forms/decidim/admin/area_form.rb
decidim-admin-0.27.1 app/forms/decidim/admin/area_form.rb
decidim-admin-0.26.4 app/forms/decidim/admin/area_form.rb
decidim-admin-0.27.0 app/forms/decidim/admin/area_form.rb
decidim-admin-0.26.3 app/forms/decidim/admin/area_form.rb
decidim-admin-0.27.0.rc2 app/forms/decidim/admin/area_form.rb
decidim-admin-0.27.0.rc1 app/forms/decidim/admin/area_form.rb
decidim-admin-0.26.2 app/forms/decidim/admin/area_form.rb