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
39
40
41
42
# 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 unless options.key? :collection_wrapper_tag
  options[:collection_wrapper_class] = 'form-group' unless options.key? :collection_wrapper_class
  if options[:inline]
    options[:item_wrapper_tag] = nil
  else
    options[:item_wrapper_tag] = :div unless options.key? :item_wrapper_tag
    options[:item_wrapper_class] = 'checkbox' unless options.key? :item_wrapper_class
  end

  if block_given?
    super
  else
    super do |input|
      input.label(options[:inline] ? { class: 'checkbox-inline' } : {} ) { input.check_box + input.text }
    end
  end
end

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/simple_form/default_form_builder.rb', line 44

def collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
  options[:collection_wrapper_tag] = :div unless options.key? :collection_wrapper_tag
  options[:collection_wrapper_class] = 'form-group' unless options.key? :collection_wrapper_class
  if options[:inline]
    options[:item_wrapper_tag] = nil
  else
    options[:item_wrapper_tag] = :div unless options.key? :item_wrapper_tag
    options[:item_wrapper_class] = 'radio' unless options.key? :item_wrapper_class
  end

  if block_given?
    super
  else
    super do |input|
      input.label(options[:inline] ? { class: 'radio-inline' } : {} ) { 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