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!(record, object, options) ⇒ Object



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

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

#fields_for(record_name, record_object = nil, options = {}, &block) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/client_side_validations/action_view/form_helper.rb', line 44

def fields_for(record_name, record_object = nil, options = {}, &block)
  # Order matters here. Rails mutates the `options` object
  output = super

  build_bound_validators! options

  output
end

#form_for(record, options = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/client_side_validations/action_view/form_helper.rb', line 10

def form_for(record, options = {}, &block)
  return super unless options[:validate]

  # We are not going to use super here, because we need
  # to inject the csv options in a data attribute in a clean way.
  # So we basically reimplement the whole form_for method
  raise ArgumentError, 'Missing block' unless block_given?

  html_options = options[:html] ||= {}

  # Moving the switch statement to another method to
  # lower complexity
  object, object_name = check_record(record, options)

  @validators = {}

  apply_html_options! options, html_options

  builder = instantiate_builder(object_name, object, options)
  output  = capture(builder, &block)
  html_options[:multipart] ||= builder.multipart?

  build_bound_validators! options

  apply_csv_html_options! html_options, options, builder
  html_options = html_options_for_form(options[:url] || {}, html_options)
  form_tag_with_body(html_options, output)
end