Module: SimpleForm::ActionViewExtensions::FormHelper

Defined in:
lib/simple_form/action_view_extensions/form_helper.rb

Overview

This module creates SimpleForm wrappers around default form_for and fields_for.

Example:

simple_form_for @user do |f|
  f.input :name, :hint => 'My hint'
end

Constant Summary collapse

FIELD_ERROR_PROC =

Override the default ActiveRecordHelper behaviour of wrapping the input. This gets taken care of semantically by adding an error class to the wrapper tag containing the input.

proc do |html_tag, instance_tag|
  html_tag
end

Instance Method Summary collapse

Instance Method Details

#simple_fields_for(record_name, record_object = nil, options = {}, &block) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/simple_form/action_view_extensions/form_helper.rb', line 33

def simple_fields_for(record_name, record_object = nil, options = {}, &block)
  options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options?
  options[:builder] ||= SimpleForm::FormBuilder

  with_simple_form_field_error_proc do
    fields_for(record_name, record_object, options, &block)
  end
end

#simple_form_for(record, options = {}, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simple_form/action_view_extensions/form_helper.rb', line 20

def simple_form_for(record, options={}, &block)
  options[:builder] ||= SimpleForm::FormBuilder
  options[:html] ||= {}
  unless options[:html].key?(:novalidate)
    options[:html][:novalidate] = !SimpleForm.browser_validations
  end
  options[:html][:class] = [SimpleForm.form_class, simple_form_css_class(record, options)].compact.join(" ")

  with_simple_form_field_error_proc do
    form_for(record, options, &block)
  end
end