Class: Miniform::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/miniform/form_builder.rb

Direct Known Subclasses

HorizontalFormBuilder, VerticalFormBuilder

Instance Method Summary collapse

Instance Method Details

#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/miniform/form_builder.rb', line 34

def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
  field_options = extract_field_options!(options)
  html_options = options_with_class(html_options, "form-control")

  Field.new(self, method, field_options) do
    super(method, collection, value_method, text_method, options, html_options)
  end.render
end

#content_tag(*args, &block) ⇒ Object



64
65
66
# File 'lib/miniform/form_builder.rb', line 64

def (*args, &block)
  @template.(*args, &block)
end

#datetime_select(method, options = {}, html_options = {}) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/miniform/form_builder.rb', line 43

def datetime_select(method, options = {}, html_options = {})
  field_options = extract_field_options!(options)
  html_options = options_with_class(html_options, "form-control")

  Field.new(self, method, field_options) do
    super(method, options, html_options)
  end.render
end

#errors(name) ⇒ Object



60
61
62
# File 'lib/miniform/form_builder.rb', line 60

def errors(name)
  object.errors[name].any? && object.errors[name].join(", ")
end

#fields_for(*args, &block) ⇒ Object



68
69
70
71
72
# File 'lib/miniform/form_builder.rb', line 68

def fields_for(*args, &block)
  options = args.extract_options!
  options[:builder] ||= Miniform::FormBuilder
  super(*args, options, &block)
end

#form_group(*names, &block) ⇒ Object



3
4
5
6
7
# File 'lib/miniform/form_builder.rb', line 3

def form_group(*names, &block)
  classes = %w[ form-group ]
  classes << "has-error" if names.any? { |n| errors(n) }
   :div, class: classes, &block
end

#help_block(name) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/miniform/form_builder.rb', line 52

def help_block(name)
  if errors(name)
    (:div, errors(name), class: "help-block")
  else
    nil
  end
end

#label(name, *args) ⇒ Object



9
10
11
12
# File 'lib/miniform/form_builder.rb', line 9

def label(name, *args)
  options = options_with_class(args.extract_options!, "control-label")
  super(name, *args, options)
end

#select(name, choices, options = {}, html_options = {}) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/miniform/form_builder.rb', line 25

def select(name, choices, options = {}, html_options = {})
  field_options = extract_field_options!(options)
  html_options = options_with_class(html_options, "form-control")

  Field.new(self, name, field_options) do
    super(name, choices, options, html_options)
  end.render
end