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] = control_class(html_options[:class], options[:object].errors[method])
  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
51
52
# 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]
  error_block = inline_help_tag(error_messages.presence)
  hint_block = (:small, class: "text-muted") do
    options[:hint]
  end if !error_messages.presence && options[:hint]

  (:div, label(object_name, method, options[:label], :class => 'control-label') +
      content + error_block + hint_block,
      class: 'form-group')
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] = control_class(options[:class], options[:object].errors[method])
  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] = control_class(options[:class], options[:object].errors[method], " form-control-file")
  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] = control_class(options[:class], options[:object].errors[method])
  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] = control_class(html_options[:class], options[:object].errors[method])
  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] = control_class(options[:class], options[:object].errors[method])
  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] = control_class(options[:class], options[:object].errors[method])
  bootstrap_control_group_wrap(object_name, method, text_field(object_name, method, extract_input_options(options)), options)
end

#inline_help_tag(messages) ⇒ Object



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

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