Module: ClientSideValidations::ActionView::Helpers::FormHelper

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

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Instance Method Details

#apply_form_for_options!(object_or_array, options) ⇒ Object



28
29
30
31
# File 'lib/client_side_validations/action_view/form_helper.rb', line 28

def apply_form_for_options!(object_or_array, options)
  super
  options[:html][:validate] = true if options[:validate]
end

#form_for(record_or_name_or_array, *args, &proc) ⇒ Object



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

def form_for(record_or_name_or_array, *args, &proc)
  options = args.extract_options!
  if options[:validate]

    # Turn off SimpleForm's HTML5 Form Validations
    if options[:builder].to_s == 'SimpleForm::FormBuilder'
      options[:html][:novalidate] = true
    end

    case record_or_name_or_array
    when String, Symbol
      raise ClientSideValidations::ActionView::Helpers::FormHelper::Error, 'Using form_for(:name, @resource) is deprecated in Rails and is not supported with ClientSideValidations. Please use form_for(@resource, :as => :name) instead.'
    when Array
      object = record_or_name_or_array.last
    else
      object = record_or_name_or_array
    end
  end

  script_tag = client_side_form_js_variable(object, options)
  "#{super(record_or_name_or_array, *(args << options), &proc)}#{script_tag}".html_safe
end