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/helpers.rb,
lib/simple_form/version.rb,
lib/simple_form/railtie.rb,
lib/simple_form/wrappers.rb,
lib/simple_form/map_type.rb,
lib/simple_form/i18n_cache.rb,
lib/simple_form/components.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/single.rb,
lib/simple_form/helpers/disabled.rb,
lib/simple_form/wrappers/builder.rb,
lib/simple_form/components/html5.rb,
lib/simple_form/helpers/required.rb,
lib/simple_form/helpers/readonly.rb,
lib/simple_form/components/hints.rb,
lib/simple_form/components/labels.rb,
lib/simple_form/components/errors.rb,
lib/simple_form/inputs/text_input.rb,
lib/simple_form/helpers/autofocus.rb,
lib/simple_form/inputs/file_input.rb,
lib/simple_form/error_notification.rb,
lib/simple_form/components/min_max.rb,
lib/simple_form/inputs/range_input.rb,
lib/simple_form/inputs/block_input.rb,
lib/simple_form/helpers/validators.rb,
lib/simple_form/components/pattern.rb,
lib/simple_form/inputs/hidden_input.rb,
lib/simple_form/components/readonly.rb,
lib/simple_form/inputs/string_input.rb,
lib/simple_form/inputs/numeric_input.rb,
lib/simple_form/inputs/boolean_input.rb,
lib/simple_form/components/maxlength.rb,
lib/simple_form/inputs/password_input.rb,
lib/simple_form/inputs/priority_input.rb,
lib/simple_form/inputs/date_time_input.rb,
lib/simple_form/components/label_input.rb,
lib/simple_form/inputs/collection_input.rb,
lib/simple_form/components/placeholders.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

VERSION =
"3.0.0.rc".freeze
@@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| "#{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
@@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
@@default_wrapper =
:default
@@wrappers =
{}

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) additional_classes_for(component)



203
204
205
# File 'lib/simple_form.rb', line 203

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)


182
183
184
185
186
187
# File 'lib/simple_form.rb', line 182

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

+ (Object) default_input_size=

SETUP



209
210
211
# File 'lib/simple_form.rb', line 209

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 SimpleForm. 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



215
216
217
# File 'lib/simple_form.rb', line 215

def self.setup
  yield self
end

+ (Object) wrapper(name)

Retrieves a given wrapper



161
162
163
# File 'lib/simple_form.rb', line 161

def self.wrapper(name)
  @@wrappers[name.to_sym] 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.



171
172
173
174
175
176
177
178
179
# File 'lib/simple_form.rb', line 171

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

Instance Method Details

- (Object) default_wrapper

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



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

mattr_accessor :default_wrapper