Module: SimpleFormWithClientValidation

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

Defined Under Namespace

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

Constant Summary collapse

DEPRECATED =

SETUP

%w(hint_tag hint_class error_tag error_class error_notification_id wrapper_tag wrapper_class wrapper_error_class components html5)
VERSION =
"0.0.2".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
@@time_zone_priority =
nil
@@country_priority =
nil
@@default_input_size =
50
@@translate_labels =
true
@@inputs_discovery =
true
@@cache_discovery =
defined?(Rails) && !Rails.env.development?
@@button_class =
'button'
@@default_wrapper =
:default
@@wrappers =
{}
@@deprecated =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.additional_classes_for(component) ⇒ Object



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

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

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

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

Yields:

  • (builder)


155
156
157
158
159
160
# File 'lib/simple_form_with_client_validation.rb', line 155

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

.deprecation_warn(message) ⇒ Object



199
200
201
# File 'lib/simple_form_with_client_validation.rb', line 199

def self.deprecation_warn(message)
  ActiveSupport::Deprecation.warn "[SIMPLE_FORM] #{message}", caller
end

.setup {|_self| ... } ⇒ Object

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

Yields:

  • (_self)

Yield Parameters:



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

def self.setup
  yield self

  unless @@deprecated.empty?
    raise "[SIMPLE FORM] Your SimpleFormWithClientValidation initializer file is using the following methods: #{@@deprecated.to_sentence}. " <<
      "Those methods are part of the outdated configuration API. Updating to the new API is easy and fast. " <<
      "Check for more info here: https://github.com/plataformatec/simple_form/wiki/Upgrading-to-Simple-Form-2.0"
  end
end

.translateObject



194
195
196
197
# File 'lib/simple_form_with_client_validation.rb', line 194

def self.translate
  deprecation_warn "SimpleFormWithClientValidation.translate is disabled in favor of translate_labels"
  self.translate_labels
end

.translate=(value) ⇒ Object



189
190
191
192
# File 'lib/simple_form_with_client_validation.rb', line 189

def self.translate=(value)
  deprecation_warn "SimpleFormWithClientValidation.translate= is disabled in favor of translate_labels="
  self.translate_labels = value
end

.wrapper(name) ⇒ Object

Retrieves a given wrapper



134
135
136
# File 'lib/simple_form_with_client_validation.rb', line 134

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

.wrappers(*args, &block) ⇒ Object

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



144
145
146
147
148
149
150
151
152
# File 'lib/simple_form_with_client_validation.rb', line 144

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

#default_wrapperObject

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



129
# File 'lib/simple_form_with_client_validation.rb', line 129

mattr_accessor :default_wrapper