Class: ExpressAdmin::SmartForm

Inherits:
ExpressTemplates::Components::Configurable
  • Object
show all
Includes:
ExpressTemplates::Components::Capabilities::Resourceful
Defined in:
app/components/express_admin/smart_form.rb

Constant Summary collapse

TIMESTAMPS =
['updated_at', 'created_at']

Instance Method Summary collapse

Instance Method Details

#form_field_for(attrib) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/components/express_admin/smart_form.rb', line 29

def form_field_for(attrib)
  field_type_substitutions = {'text_area'       => 'textarea',
                              'datetime_select' => 'datetime',
                              'check_box'       => 'checkbox'}
  field_type = attrib.field_type.to_s.sub(/_field$/,'')
  if relation = attrib.name.match(/(\w+)_id$/).try(:[], 1)
      # TODO: should allow select2 override
      select(attrib.name, options: config["#{relation}_collection".to_sym], select2: true)
  else
    if field_type == 'text_area'
      textarea attrib.name.to_sym, rows: 10
    else
      self.send((field_type_substitutions[field_type] || field_type), attrib.name.to_sym)
    end
  end
end