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
32
|
# File 'lib/client_side_validations/adapters/action_view.rb', line 6
def self.included(base)
form_method = base.instance_method(:form_for)
base.class_eval do
attr_accessor :validate_options
define_method(:form_for) do |record_or_name_or_array, *args, &proc|
options = args..symbolize_keys!
script = ""
if validations = options.delete(:validations)
set_validate_options(validations, record_or_name_or_array, options)
unless options.has_key?(:html)
options[:html] = {}
end
options[:html]['data-csv'] = validate_options.delete('data-csv')
script = %{<script type='text/javascript'>var #{options[:html]['data-csv']}_validate_options=#{validate_options.to_json};</script>}
end
args << options
result = form_method.bind(self).call(record_or_name_or_array, *args, &proc)
if rails3?
result += script.html_safe
else
concat(script)
end
result
end
end
end
|