Module: ActionView::Helpers::FormHelper

Defined in:
lib/bootstrap-form/form_helper.rb

Constant Summary collapse

BOOTSTRAP_OPTIONS =
[:label, :hint].freeze

Instance Method Summary collapse

Instance Method Details

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



22
23
24
25
# File 'lib/bootstrap-form/form_helper.rb', line 22

def bootstrap_collection_select(object_name, method, collection, value_method, text_method, options = {}, html_options = {})
  html_options[:class] = (html_options[:class] ? html_options[:class] + " form-control" : "form-control")
  bootstrap_control_group_wrap(object_name, method, collection_select(object_name, method, collection, value_method, text_method, extract_input_options(options), html_options), options)
end

#bootstrap_control_group_wrap(object_name, method, content, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/bootstrap-form/form_helper.rb', line 42

def bootstrap_control_group_wrap(object_name, method, content, options={})
  error_messages    = options[:object].errors[method]
  control_group_tag = error_messages.blank? ? 'form-group' : 'form-group has-error'
  inline_help       = inline_help_tag(error_messages.presence || options[:hint])

  (:div, label(object_name, method, options[:label], :class => 'control-label') +
      content + inline_help,
      :class => control_group_tag)
end

#bootstrap_email_field(object_name, method, options = {}) ⇒ Object



12
13
14
15
# File 'lib/bootstrap-form/form_helper.rb', line 12

def bootstrap_email_field(object_name, method, options={})
  options[:class] = (options[:class] ? options[:class] + " form-control" : "form-control")
  bootstrap_control_group_wrap(object_name, method, email_field(object_name, method, extract_input_options(options)), options)
end

#bootstrap_file_field(object_name, method, options = {}) ⇒ Object



32
33
34
35
# File 'lib/bootstrap-form/form_helper.rb', line 32

def bootstrap_file_field(object_name, method, options={})
  options[:class] = (options[:class] ? options[:class] + " form-control" : "form-control")
  bootstrap_control_group_wrap(object_name, method, file_field(object_name, method, extract_input_options(options)), options)
end

#bootstrap_password_field(object_name, method, options = {}) ⇒ Object



17
18
19
20
# File 'lib/bootstrap-form/form_helper.rb', line 17

def bootstrap_password_field(object_name, method, options={})
  options[:class] = (options[:class] ? options[:class] + " form-control" : "form-control")
  bootstrap_control_group_wrap(object_name, method, password_field(object_name, method, extract_input_options(options)), options)
end

#bootstrap_select(object_name, method, choices, options = {}, html_options = {}) ⇒ Object



27
28
29
30
# File 'lib/bootstrap-form/form_helper.rb', line 27

def bootstrap_select(object_name, method, choices, options={}, html_options={})
  html_options[:class] = (html_options[:class] ? html_options[:class] + " form-control" : "form-control")
  bootstrap_control_group_wrap(object_name, method, select(object_name, method, choices, extract_input_options(options), html_options), options)
end

#bootstrap_text_area(object_name, method, options = {}) ⇒ Object



37
38
39
40
# File 'lib/bootstrap-form/form_helper.rb', line 37

def bootstrap_text_area(object_name, method, options={})
  options[:class] = (options[:class] ? options[:class] + " form-control" : "form-control")
  bootstrap_control_group_wrap(object_name, method, text_area(object_name, method, extract_input_options(options)), options)
end

#bootstrap_text_field(object_name, method, options = {}) ⇒ Object



7
8
9
10
# File 'lib/bootstrap-form/form_helper.rb', line 7

def bootstrap_text_field(object_name, method, options={})
  options[:class] = (options[:class] ? options[:class] + " form-control" : "form-control")
  bootstrap_control_group_wrap(object_name, method, text_field(object_name, method, extract_input_options(options)), options)
end

#inline_help_tag(messages) ⇒ Object



52
53
54
55
56
57
# File 'lib/bootstrap-form/form_helper.rb', line 52

def inline_help_tag(messages)
  messages = Array.wrap(messages)
  return '' if messages.empty?
  message_span = ActiveSupport::SafeBuffer.new(" #{messages.to_sentence}")
  (:span, message_span, :class => 'help-block')
end