Module: ClientSideValidations::SimpleForm::FormBuilder

Defined in:
lib/client_side_validations/simple_form/form_builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
# File 'lib/client_side_validations/simple_form/form_builder.rb', line 4

def self.included(base)
  base.class_eval do
    alias_method_chain :input, :client_side_validations
  end
end

Instance Method Details

#client_side_form_settings(options, _form_helper) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/client_side_validations/simple_form/form_builder.rb', line 10

def client_side_form_settings(options, _form_helper)
  {
    type: self.class.to_s,
    error_class: wrapper.find(:error).defaults[:class].first,
    error_tag: wrapper.find(:error).defaults[:tag],
    wrapper_error_class: wrapper.defaults[:error_class],
    wrapper_tag: wrapper.defaults[:tag],
    wrapper_class: wrapper.defaults[:class].first,
    wrapper: options[:wrapper] || ::SimpleForm.default_wrapper
  }
end

#input_with_client_side_validations(attribute_name, options = {}, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/client_side_validations/simple_form/form_builder.rb', line 22

def input_with_client_side_validations(attribute_name, options = {}, &block)
  if options.key?(:validate)
    options[:input_html] ||= {}
    options[:input_html][:validate] = options[:validate]
    options.delete(:validate)
  end

  input_without_client_side_validations(attribute_name, options, &block)
end