Class: SimpleForm::DefaultFormBuilder

Inherits:
FormBuilder
  • Object
show all
Defined in:
lib/simple_form/default_form_builder.rb

Constant Summary collapse

CHECKBOX_WRAPPER =
:checkbox
RADIO_WRAPPER =
:radio

Instance Method Summary collapse

Instance Method Details

#checkbox(attribute_name, options = {}, &block) ⇒ Object



9
10
11
12
13
# File 'lib/simple_form/default_form_builder.rb', line 9

def checkbox(attribute_name, options = {}, &block)
  options[:wrapper] ||= self.class::CHECKBOX_WRAPPER
  options[:as] ||= :boolean
  input attribute_name, options, &block
end

#collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/simple_form/default_form_builder.rb', line 25

def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
  options[:collection_wrapper_tag] ||= :div
  options[:collection_wrapper_class] ||= 'form-group'
  options[:item_wrapper_tag] ||= :div
  options[:item_wrapper_class] ||= 'checkbox'

  if block_given?
    super
  else
    super do |input|
      input.label { input.check_box + input.text }
    end
  end
end

#collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/simple_form/default_form_builder.rb', line 40

def collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
  options[:collection_wrapper_tag] ||= :div
  options[:collection_wrapper_class] ||= 'form-group'
  options[:item_wrapper_tag] ||= :div
  options[:item_wrapper_class] ||= 'radio'

  if block_given?
    super
  else
    super do |input|
      input.label { input.radio_button + input.text }
    end
  end
end

#input(attribute_name, options = {}, &block) ⇒ Object



20
21
22
23
# File 'lib/simple_form/default_form_builder.rb', line 20

def input(attribute_name, options = {}, &block)
  options[:wrapper] ||= self.class::CHECKBOX_WRAPPER if options[:as] == :boolean
  super
end

#radio(attribute_name, options = {}, &block) ⇒ Object



15
16
17
18
# File 'lib/simple_form/default_form_builder.rb', line 15

def radio(attribute_name, options = {}, &block)
  options[:wrapper] ||= self.class::RADIO_WRAPPER
  input attribute_name, options, &block
end