Class: Decidim::CustomUserFields::Fields::TextAreaField

Inherits:
GenericField
  • Object
show all
Defined in:
lib/decidim/custom_user_fields/fields/text_area_field.rb

Instance Attribute Summary

Attributes inherited from GenericField

#definition, #options

Instance Method Summary collapse

Methods inherited from GenericField

#class_name, #initialize, #required?

Constructor Details

This class inherits a constructor from Decidim::CustomUserFields::Fields::GenericField

Instance Method Details

#configure_form(form) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/decidim/custom_user_fields/fields/text_area_field.rb', line 5

def configure_form(form)
  form.attribute(name, String)
  form.validates(name, presence: required?)
  if options[:min].present? || options[:max].present?
    min_max_options = {}
    min_max_options[:minimum] = options[:min].to_i if options[:min].present?
    min_max_options[:maximum] = options[:max].to_i if options[:max].present?
    form.validates(name, length: min_max_options, allow_blank: !required?)
  end
end

#form_tag(form_tag) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/decidim/custom_user_fields/fields/text_area_field.rb', line 20

def form_tag(form_tag)
  field_options = {
    rows: options[:row] || 2
  }
  (
    :div,
    form_tag.text_area(name, **field_options),
    class: class_name
  )
end

#map_model(form, data) ⇒ Object



16
17
18
# File 'lib/decidim/custom_user_fields/fields/text_area_field.rb', line 16

def map_model(form, data)
  form[name] = data[name] if data[name].present?
end