Module: SimpleForm

Extended by:
ActiveSupport::Autoload
Defined in:
lib/simple_form.rb,
lib/simple_form/tags.rb,
lib/simple_form/inputs.rb,
lib/simple_form/version.rb,
lib/simple_form/railtie.rb,
lib/simple_form/helpers.rb,
lib/simple_form/map_type.rb,
lib/simple_form/wrappers.rb,
lib/simple_form/components.rb,
lib/simple_form/i18n_cache.rb,
lib/simple_form/inputs/base.rb,
lib/simple_form/form_builder.rb,
lib/simple_form/wrappers/root.rb,
lib/simple_form/wrappers/many.rb,
lib/simple_form/wrappers/leaf.rb,
lib/simple_form/wrappers/single.rb,
lib/simple_form/helpers/readonly.rb,
lib/simple_form/components/html5.rb,
lib/simple_form/helpers/required.rb,
lib/simple_form/wrappers/builder.rb,
lib/simple_form/components/hints.rb,
lib/simple_form/helpers/disabled.rb,
lib/simple_form/inputs/text_input.rb,
lib/simple_form/components/labels.rb,
lib/simple_form/inputs/file_input.rb,
lib/simple_form/components/errors.rb,
lib/simple_form/helpers/autofocus.rb,
lib/simple_form/helpers/validators.rb,
lib/simple_form/inputs/block_input.rb,
lib/simple_form/components/pattern.rb,
lib/simple_form/inputs/range_input.rb,
lib/simple_form/components/min_max.rb,
lib/simple_form/error_notification.rb,
lib/simple_form/components/readonly.rb,
lib/simple_form/inputs/hidden_input.rb,
lib/simple_form/inputs/string_input.rb,
lib/simple_form/inputs/boolean_input.rb,
lib/simple_form/components/maxlength.rb,
lib/simple_form/inputs/numeric_input.rb,
lib/simple_form/inputs/priority_input.rb,
lib/simple_form/inputs/password_input.rb,
lib/simple_form/inputs/date_time_input.rb,
lib/simple_form/components/label_input.rb,
lib/simple_form/components/placeholders.rb,
lib/simple_form/inputs/collection_input.rb,
lib/generators/simple_form/install_generator.rb,
lib/simple_form/inputs/collection_select_input.rb,
lib/simple_form/action_view_extensions/builder.rb,
lib/simple_form/action_view_extensions/form_helper.rb,
lib/simple_form/inputs/collection_check_boxes_input.rb,
lib/simple_form/inputs/collection_radio_buttons_input.rb,
lib/simple_form/inputs/grouped_collection_select_input.rb

Defined Under Namespace

Modules: ActionViewExtensions, Components, Generators, Helpers, I18nCache, Inputs, MapType, Tags, Wrappers Classes: ErrorNotification, FormBuilder, Railtie, WrapperNotFound

Constant Summary

CUSTOM_INPUT_DEPRECATION_WARN =
<<-WARN
%{name} method now accepts a `wrapper_options` argument. The method definition without the argument is deprecated and will be removed in the next Simple Form version. Change your code from:

  def %{name}

to

  def %{name}(wrapper_options)

See https://github.com/plataformatec/simple_form/pull/997 for more information.
WARN
VERSION =
"3.1.0.rc2".freeze
@@configured =
false
@@error_method =
:first
@@error_notification_tag =
:p
@@error_notification_class =
:error_notification
@@collection_label_methods =
[:to_label, :name, :title, :to_s]
@@collection_value_methods =
[:id, :to_s]
@@collection_wrapper_tag =
nil
@@collection_wrapper_class =
nil
@@item_wrapper_tag =
:span
@@item_wrapper_class =
nil
@@label_text =
lambda { |label, required, explicit_label| "#{required} #{label}" }
@@label_class =
nil
@@boolean_style =
:inline
@@form_class =
:simple_form
@@generate_additional_classes_for =
[:wrapper, :label, :input]
@@required_by_default =
true
@@browser_validations =
true
@@file_methods =
[:mounted_as, :file?, :public_filename]
@@input_mappings =
nil
@@wrapper_mappings =
nil
@@custom_inputs_namespaces =
[]
@@time_zone_priority =
nil
@@country_priority =
nil
@@default_input_size =
nil
@@translate_labels =
true
@@inputs_discovery =
true
@@cache_discovery =
defined?(Rails) && !Rails.env.development?
@@button_class =
'button'
@@field_error_proc =
proc do |html_tag, instance_tag|
  html_tag
end
@@input_class =
nil
@@include_default_input_wrapper_class =
true
@@boolean_label_class =
'checkbox'
@@default_wrapper =
:default
@@wrappers =

:nodoc:

{}
@@i18n_scope =
'simple_form'

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) additional_classes_for(component)



242
243
244
# File 'lib/simple_form.rb', line 242

def self.additional_classes_for(component)
  generate_additional_classes_for.include?(component) ? yield : []
end

+ (Object) build(options = {}) {|builder| ... }

Builds a new wrapper using SimpleForm::Wrappers::Builder.

Yields:

  • (builder)


221
222
223
224
225
226
# File 'lib/simple_form.rb', line 221

def self.build(options = {})
  options[:tag] = :div if options[:tag].nil?
  builder = SimpleForm::Wrappers::Builder.new(options)
  yield builder
  SimpleForm::Wrappers::Root.new(builder.to_a, options)
end

+ (Boolean) configured?

:nodoc:

Returns:

  • (Boolean)


41
42
43
# File 'lib/simple_form.rb', line 41

def self.configured? #:nodoc:
  @@configured
end

+ (Object) default_input_size=

SETUP



248
249
250
# File 'lib/simple_form.rb', line 248

def self.default_input_size=(*)
  ActiveSupport::Deprecation.warn "[SIMPLE_FORM] SimpleForm.default_input_size= is deprecated and has no effect", caller
end

+ (Object) eager_load!



21
22
23
24
25
# File 'lib/simple_form.rb', line 21

def self.eager_load!
  super
  SimpleForm::Inputs.eager_load!
  SimpleForm::Components.eager_load!
end

+ (Object) setup {|_self| ... }

Default way to setup Simple Form. Run rails generate simple_form:install to create a fresh initializer with all configuration values.

Yields:

  • (_self)

Yield Parameters:

  • _self (SimpleForm)

    the object that the method was called on



254
255
256
257
# File 'lib/simple_form.rb', line 254

def self.setup
  @@configured = true
  yield self
end

+ (Object) wrapper(name)

Retrieves a given wrapper



200
201
202
# File 'lib/simple_form.rb', line 200

def self.wrapper(name)
  @@wrappers[name.to_s] or raise WrapperNotFound, "Couldn't find wrapper with name #{name}"
end

+ (Object) wrappers(*args, &block)

Define a new wrapper using SimpleForm::Wrappers::Builder and store it in the given name.



210
211
212
213
214
215
216
217
218
# File 'lib/simple_form.rb', line 210

def self.wrappers(*args, &block)
  if block_given?
    options                 = args.extract_options!
    name                    = args.first || :default
    @@wrappers[name.to_s]   = build(options, &block)
  else
    @@wrappers
  end
end

Instance Method Details

- (Object) default_wrapper

WRAPPER CONFIGURATION The default wrapper to be used by the FormBuilder.



192
# File 'lib/simple_form.rb', line 192

mattr_accessor :default_wrapper