Class: Formtastic::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Extended by:
Helpers::ActionHelper, Helpers::ActionsHelper, Helpers::ErrorsHelper, Helpers::InputHelper, Helpers::InputsHelper
Defined in:
lib/formtastic/form_builder.rb

Constant Summary

Constants included from Helpers::ErrorsHelper

Helpers::ErrorsHelper::INLINE_ERROR_TYPES

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Helpers::ErrorsHelper

semantic_errors

Methods included from LocalizedString

#model_name

Methods included from Helpers::ActionsHelper

actions

Methods included from Helpers::ActionHelper

action

Methods included from Helpers::InputsHelper

inputs

Methods included from Helpers::InputHelper

input

Class Attribute Details

.action_class_finderObject

TODO:

enable this as default in 4.0 and remove it from configuration generator template

Will be ActionClassFinder by default in 4.0.



52
# File 'lib/formtastic/form_builder.rb', line 52

configure :action_class_finder

.action_namespacesObject

Check ActionClassFinder to see how are inputs resolved.



49
# File 'lib/formtastic/form_builder.rb', line 49

configure :action_namespaces, [::Object, ::Formtastic::Actions]

.all_fields_required_by_defaultObject



22
# File 'lib/formtastic/form_builder.rb', line 22

configure :all_fields_required_by_default, true

.auto_indexObject (readonly)

Returns the value of attribute auto_index.



59
60
61
# File 'lib/formtastic/form_builder.rb', line 59

def auto_index
  @auto_index
end

.collection_label_methodsObject



28
# File 'lib/formtastic/form_builder.rb', line 28

configure :collection_label_methods, %w[to_label display_name full_name name title username login value to_s]

.collection_value_methodsObject



29
# File 'lib/formtastic/form_builder.rb', line 29

configure :collection_value_methods, %w[id to_s]

.custom_namespaceObject



18
# File 'lib/formtastic/form_builder.rb', line 18

configure :custom_namespace

.default_commit_button_accesskeyObject



37
# File 'lib/formtastic/form_builder.rb', line 37

configure :default_commit_button_accesskey

.default_error_list_classObject



39
# File 'lib/formtastic/form_builder.rb', line 39

configure :default_error_list_class, 'errors'

.default_hint_classObject



40
# File 'lib/formtastic/form_builder.rb', line 40

configure :default_hint_class, 'inline-hints'

.default_inline_error_classObject



38
# File 'lib/formtastic/form_builder.rb', line 38

configure :default_inline_error_class, 'inline-errors'

.default_text_area_heightObject



20
# File 'lib/formtastic/form_builder.rb', line 20

configure :default_text_area_height, 20

.default_text_area_widthObject



21
# File 'lib/formtastic/form_builder.rb', line 21

configure :default_text_area_width

.default_text_field_sizeObject



19
# File 'lib/formtastic/form_builder.rb', line 19

configure :default_text_field_size

.escape_html_entities_in_hints_and_labelsObject



36
# File 'lib/formtastic/form_builder.rb', line 36

configure :escape_html_entities_in_hints_and_labels, true

.file_metadata_suffixesObject



31
# File 'lib/formtastic/form_builder.rb', line 31

configure :file_metadata_suffixes, ['content_type', 'file_name', 'file_size']

.file_methodsObject



30
# File 'lib/formtastic/form_builder.rb', line 30

configure :file_methods, [ :file?, :public_filename, :filename ]

.i18n_cache_lookupsObject



34
# File 'lib/formtastic/form_builder.rb', line 34

configure :i18n_cache_lookups, true

.i18n_localizerObject



35
# File 'lib/formtastic/form_builder.rb', line 35

configure :i18n_localizer, Formtastic::Localizer

.i18n_lookups_by_defaultObject



33
# File 'lib/formtastic/form_builder.rb', line 33

configure :i18n_lookups_by_default, true

.include_blank_for_select_by_defaultObject



23
# File 'lib/formtastic/form_builder.rb', line 23

configure :include_blank_for_select_by_default, true

.inline_errorsObject



26
# File 'lib/formtastic/form_builder.rb', line 26

configure :inline_errors, :sentence

.input_class_finderObject

TODO:

enable this as default in 4.0 and remove it from configuration generator template

Will be InputClassFinder by default in 4.0.



47
# File 'lib/formtastic/form_builder.rb', line 47

configure :input_class_finder

.input_namespacesObject

Check InputClassFinder to see how are inputs resolved.



44
# File 'lib/formtastic/form_builder.rb', line 44

configure :input_namespaces, [::Object, ::Formtastic::Inputs]

.label_str_methodObject



27
# File 'lib/formtastic/form_builder.rb', line 27

configure :label_str_method, :humanize

.optional_stringObject



25
# File 'lib/formtastic/form_builder.rb', line 25

configure :optional_string, ''

.perform_browser_validationsObject



42
# File 'lib/formtastic/form_builder.rb', line 42

configure :perform_browser_validations, false

.priority_countriesObject



32
# File 'lib/formtastic/form_builder.rb', line 32

configure :priority_countries, ["Australia", "Canada", "United Kingdom", "United States"]

.priority_time_zonesObject



55
# File 'lib/formtastic/form_builder.rb', line 55

configure :priority_time_zones, []

.required_stringObject



24
# File 'lib/formtastic/form_builder.rb', line 24

configure :required_string, proc { Formtastic::Util.html_safe(%{<abbr title="#{Formtastic::I18n.t(:required)}">*</abbr>}) }

.skipped_columnsObject



54
# File 'lib/formtastic/form_builder.rb', line 54

configure :skipped_columns, [:created_at, :updated_at, :created_on, :updated_on, :lock_version, :version]

.templateObject (readonly)

Returns the value of attribute template.



57
58
59
# File 'lib/formtastic/form_builder.rb', line 57

def template
  @template
end

.use_required_attributeObject



41
# File 'lib/formtastic/form_builder.rb', line 41

configure :use_required_attribute, false

Class Method Details

.initialize(object_name, object, template, options, block = nil) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/formtastic/form_builder.rb', line 106

def initialize(object_name, object, template, options, block=nil)
  # rails 3 supported passing in the block parameter to FormBuilder
  # rails 4.0 deprecated the block parameter and does nothing with it
  # rails 4.1 removes the parameter completely
  if Util.rails3? || Util.rails4_0?
    super
  else # Must be rails4_1 or greater
    super object_name, object, template, options
  end

  if respond_to?('multipart=') && options.is_a?(Hash) && options[:html]
    self.multipart = options[:html][:multipart]
  end
end

.semantic_fields_for(record_or_name_or_array, *args, &block) ⇒ Object

TODO:

is there a way to test the params structure of the Rails helper we wrap to ensure forward compatibility?

This is a wrapper around Rails' ActionView::Helpers::FormBuilder#fields_for, originally provided to ensure that the :builder from semantic_form_for was passed down into the nested fields_for. Rails 3 no longer requires us to do this, so this method is provided purely for backwards compatibility and DSL consistency.

When constructing a fields_for form fragment outside of semantic_form_for, please use Formtastic::Helpers::FormHelper#semantic_fields_for.

Examples:

<% semantic_form_for @post do |post| %>
  <% post.semantic_fields_for :author do |author| %>
    <% author.inputs :name %>
  <% end %>
<% end %>

<form ...>
  <fieldset class="inputs">
    <ol>
      <li class="string"><input type='text' name='post[author][name]' id='post_author_name' /></li>
    </ol>
  </fieldset>
</form>

See Also:



97
98
99
100
101
102
103
104
# File 'lib/formtastic/form_builder.rb', line 97

def semantic_fields_for(record_or_name_or_array, *args, &block)
  # Add a :parent_builder to the args so that nested translations can be possible in Rails 3
  options = args.extract_options!
  options[:parent_builder] ||= self

  # Wrap the Rails helper
  fields_for(record_or_name_or_array, *(args << options), &block)
end