Sha256: 88c8f2fa48550164fba8d577d02ebff0e1739b60e123803c510bb13324253045

Contents?: true

Size: 911 Bytes

Versions: 13

Compression:

Stored size: 911 Bytes

Contents

= Forms

This is a form example that can be implemented in your application.

Form classes are located in the `app/forms/decidim/<my_module>` directory, and named: `<resource>_form.rb`.

```ruby
# frozen_string_literal: true

# app/forms/decidim/my_module/resource_form.rb
module Decidim
  module MyModule
    class ResourceForm < Decidim::Form
      include Decidim::TranslatableAttributes

      attribute :title, String
      translatable_attribute :body, String

      validates :title, length: { maximum: 150 }, translatable_presence: true
      validates :body, translatable_presence: true

      validate :some_custom_validation

      private

      def some_custom_validation
        errors.add(:title, :invalid) if title == "invalid"
      end
    end
  end
end
```

== More information

- `Decidim::Form` is an internalization of https://github.com/andypike/rectify[Rectify] gem created by Andy Pike

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-0.29.1 docs/modules/develop/pages/classes/forms.adoc
decidim-0.28.4 docs/modules/develop/pages/classes/forms.adoc
decidim-0.29.0 docs/modules/develop/pages/classes/forms.adoc
decidim-0.28.3 docs/modules/develop/pages/classes/forms.adoc
decidim-0.29.0.rc4 docs/modules/develop/pages/classes/forms.adoc
decidim-0.29.0.rc3 docs/modules/develop/pages/classes/forms.adoc
decidim-0.29.0.rc2 docs/modules/develop/pages/classes/forms.adoc
decidim-0.29.0.rc1 docs/modules/develop/pages/classes/forms.adoc
decidim-0.28.2 docs/modules/develop/pages/classes/forms.adoc
decidim-0.28.1 docs/modules/develop/pages/classes/forms.adoc
decidim-0.28.0 docs/modules/develop/pages/classes/forms.adoc
decidim-0.28.0.rc5 docs/modules/develop/pages/classes/forms.adoc
decidim-0.28.0.rc4 docs/modules/develop/pages/classes/forms.adoc