Class: Decidim::CustomUserFields::Fields::DateField

Inherits:
GenericField
  • Object
show all
Defined in:
lib/decidim/custom_user_fields/fields/date_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
# File 'lib/decidim/custom_user_fields/fields/date_field.rb', line 5

def configure_form(form)
  form.attribute(name, String)
  form.validates(name, presence: required?)
end

#form_tag(form_tag) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/decidim/custom_user_fields/fields/date_field.rb', line 14

def form_tag(form_tag)
  field_options = {}
  if options[:min].present? || options[:max].present?
    field_options[:min] = options[:min] if options[:min].present?
    field_options[:max] = options[:max] if options[:max].present?
  end

  (
    :div,
    form_tag.date_field(name, **field_options),
    class: class_name
  )
end

#map_model(form, data) ⇒ Object



10
11
12
# File 'lib/decidim/custom_user_fields/fields/date_field.rb', line 10

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