Class: Godmin::FormBuilders::FormBuilder

Inherits:
BootstrapForm::FormBuilder
  • Object
show all
Defined in:
lib/godmin/helpers/forms.rb

Instance Method Summary collapse

Instance Method Details

#association(attribute, options = {}, html_options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/godmin/helpers/forms.rb', line 31

def association(attribute, options = {}, html_options = {})
  case association_type(attribute)
  when :belongs_to
    select("#{attribute}_id", association_collection_for_select(attribute), options, html_options.deep_merge(
      data: { behavior: "select-box" }
    ))
  else
    input(attribute, options)
  end
end

#date_field(attribute, options = {}) ⇒ Object



42
43
44
45
46
47
# File 'lib/godmin/helpers/forms.rb', line 42

def date_field(attribute, options = {})
  text_field(attribute, options.deep_merge(
    value: datetime_value(attribute, options, :datepicker),
    data: { behavior: "datepicker" }
  ))
end

#datetime_field(attribute, options = {}) ⇒ Object



49
50
51
52
53
54
# File 'lib/godmin/helpers/forms.rb', line 49

def datetime_field(attribute, options = {})
  text_field(attribute, options.deep_merge(
    value: datetime_value(attribute, options, :datetimepicker),
    data: { behavior: "datetimepicker" }
  ))
end

#input(attribute, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/godmin/helpers/forms.rb', line 16

def input(attribute, options = {})
  case attribute_type(attribute)
  when :text
    text_area(attribute, options)
  when :boolean
    check_box(attribute, options)
  when :date
    date_field(attribute, options)
  when :datetime
    datetime_field(attribute, options)
  else
    text_field(attribute, options)
  end
end