Module: ClientSideValidations::ActionView::Helpers::FormBuilder

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/client_side_validations/action_view/form_builder.rb', line 4

def self.included(base)
  (base.field_helpers - %w(apply_form_for_options! label check_box radio_button fields_for hidden_field)).each do |selector|
    base.class_eval <<-RUBY_EVAL
      def #{selector}_with_client_side_validations(method, options = {})
        apply_client_side_validators(method, options)
        options.delete(:validate)
        #{selector}_without_client_side_validations(method, options)
      end
    RUBY_EVAL

    base.class_eval { alias_method_chain selector, :client_side_validations }
  end

  base.class_eval do
    alias_method_chain :initialize,   :client_side_validations
    alias_method_chain :fields_for,   :client_side_validations
    alias_method_chain :check_box,    :client_side_validations
    alias_method_chain :radio_button, :client_side_validations

    def self.client_side_form_settings(options, form_helper)
      {
        :type => self.to_s,
        :input_tag => form_helper.class.field_error_proc.call(%{<span id="input_tag" />}, Struct.new(:error_message, :tag_id).new([], "")),
        :label_tag => form_helper.class.field_error_proc.call(%{<label id="label_tag" />})
      }
    end
  end
end

Instance Method Details

#check_box_with_client_side_validations(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object



44
45
46
47
# File 'lib/client_side_validations/action_view/form_builder.rb', line 44

def check_box_with_client_side_validations(method, options = {}, checked_value = "1", unchecked_value = "0")
  apply_client_side_validators(method, options)
  check_box_without_client_side_validations(method, options, checked_value, unchecked_value)
end

#fields_for_with_client_side_validations(record_or_name_or_array, *args, &block) ⇒ Object



38
39
40
41
42
# File 'lib/client_side_validations/action_view/form_builder.rb', line 38

def fields_for_with_client_side_validations(record_or_name_or_array, *args, &block)
  options = args.extract_options!
  options[:validate] ||= @options[:validate] if @options[:validate] && !options.key?(:validate)
  fields_for_without_client_side_validations(record_or_name_or_array, *(args << options), &block)
end

#initialize_with_client_side_validations(object_name, object, template, options, proc) ⇒ Object



33
34
35
36
# File 'lib/client_side_validations/action_view/form_builder.rb', line 33

def initialize_with_client_side_validations(object_name, object, template, options, proc)
  initialize_without_client_side_validations(object_name, object, template, options, proc)
  @options[:validators] = {}
end

#radio_button_with_client_side_validations(method, tag_value, options = {}) ⇒ Object



49
50
51
52
# File 'lib/client_side_validations/action_view/form_builder.rb', line 49

def radio_button_with_client_side_validations(method, tag_value, options = {})
  apply_client_side_validators(method, options)
  radio_button_without_client_side_validations(method, tag_value, options)
end