module ActionView::Helpers::FormHelper

Constants

BOOTSTRAP_OPTIONS

Public Instance Methods

bootstrap_collection_select(object_name, method, collection, value_method, text_method, options = {}, html_options = {}) click to toggle source
# 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={}) click to toggle source
# 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 = content_tag(:small, class: "text-muted") do
    options[:hint]
  end if !error_messages.presence && options[:hint]

  content_tag(: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={}) click to toggle source
# 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={}) click to toggle source
# 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={}) click to toggle source
# 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={}) click to toggle source
# 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={}) click to toggle source
# 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={}) click to toggle source
# 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) click to toggle source
# 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}")
  content_tag(:div, message_span, class: 'invalid-feedback')
end

Private Instance Methods

control_class(current_class, errors=[], bootstrap_class=" form-control") click to toggle source
# File lib/bootstrap-form/form_helper.rb, line 67
def control_class(current_class, errors=[], bootstrap_class=" form-control")
  css_class = current_class || ""
  css_class << bootstrap_class
  css_class << " is-invalid" if errors.any?
  css_class
end
extract_input_options(options) click to toggle source
# File lib/bootstrap-form/form_helper.rb, line 63
def extract_input_options(options)
  options.except(*BOOTSTRAP_OPTIONS)
end