client_side_validations 3.2.5 → 4.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +558 -0
- data/lib/client_side_validations/action_view/form_builder.rb +102 -84
- data/lib/client_side_validations/action_view/form_helper.rb +106 -111
- data/lib/client_side_validations/action_view/form_tag_helper.rb +13 -9
- data/lib/client_side_validations/action_view.rb +4 -3
- data/lib/client_side_validations/active_model/absence.rb +11 -0
- data/lib/client_side_validations/active_model/acceptance.rb +7 -6
- data/lib/client_side_validations/active_model/conditionals.rb +41 -0
- data/lib/client_side_validations/active_model/exclusion.rb +4 -24
- data/lib/client_side_validations/active_model/format.rb +14 -19
- data/lib/client_side_validations/active_model/inclusion.rb +4 -23
- data/lib/client_side_validations/active_model/length.rb +15 -15
- data/lib/client_side_validations/active_model/numericality.rb +25 -27
- data/lib/client_side_validations/active_model/presence.rb +7 -6
- data/lib/client_side_validations/active_model.rb +90 -82
- data/lib/client_side_validations/active_record/middleware.rb +48 -42
- data/lib/client_side_validations/active_record/uniqueness.rb +25 -21
- data/lib/client_side_validations/active_record.rb +5 -6
- data/lib/client_side_validations/config.rb +1 -1
- data/lib/client_side_validations/core_ext/range.rb +1 -2
- data/lib/client_side_validations/core_ext/regexp.rb +6 -4
- data/lib/client_side_validations/engine.rb +0 -1
- data/lib/client_side_validations/generators/rails_validations.rb +2 -3
- data/lib/client_side_validations/generators.rb +6 -3
- data/lib/client_side_validations/middleware.rb +37 -28
- data/lib/client_side_validations/version.rb +2 -1
- data/lib/client_side_validations.rb +0 -1
- data/lib/generators/client_side_validations/copy_assets_generator.rb +21 -25
- data/lib/generators/client_side_validations/install_generator.rb +0 -4
- data/lib/generators/templates/client_side_validations/initializer.rb +5 -2
- data/vendor/assets/javascripts/rails.validations.js +120 -100
- metadata +175 -62
- data/client_side_validations.gemspec +0 -32
|
@@ -1,104 +1,122 @@
|
|
|
1
|
-
module ClientSideValidations
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
module ClientSideValidations
|
|
2
|
+
module ActionView
|
|
3
|
+
module Helpers
|
|
4
|
+
module FormBuilder
|
|
5
|
+
def self.included(base)
|
|
6
|
+
(base.field_helpers.map(&:to_s) - %w(apply_form_for_options! label check_box radio_button fields_for hidden_field)).each do |selector|
|
|
7
|
+
base.class_eval <<-RUBY_EVAL
|
|
8
|
+
def #{selector}_with_client_side_validations(method, options = {})
|
|
9
|
+
build_validation_options(method, options)
|
|
10
|
+
options.delete(:validate)
|
|
11
|
+
#{selector}_without_client_side_validations(method, options)
|
|
12
|
+
end
|
|
13
|
+
RUBY_EVAL
|
|
14
|
+
|
|
15
|
+
base.class_eval { alias_method_chain selector, :client_side_validations }
|
|
11
16
|
end
|
|
12
|
-
RUBY_EVAL
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
base.class_eval do
|
|
19
|
+
alias_method_chain :initialize, :client_side_validations
|
|
20
|
+
alias_method_chain :fields_for, :client_side_validations
|
|
21
|
+
alias_method_chain :check_box, :client_side_validations
|
|
22
|
+
alias_method_chain :radio_button, :client_side_validations
|
|
23
|
+
alias_method_chain :select, :client_side_validations
|
|
24
|
+
alias_method_chain :collection_select, :client_side_validations
|
|
25
|
+
alias_method_chain :collection_check_boxes, :client_side_validations
|
|
26
|
+
alias_method_chain :collection_radio_buttons, :client_side_validations
|
|
27
|
+
alias_method_chain :grouped_collection_select, :client_side_validations
|
|
28
|
+
alias_method_chain :time_zone_select, :client_side_validations
|
|
29
|
+
end
|
|
30
|
+
end
|
|
16
31
|
|
|
17
|
-
|
|
18
|
-
alias_method_chain :initialize, :client_side_validations
|
|
19
|
-
alias_method_chain :fields_for, :client_side_validations
|
|
20
|
-
alias_method_chain :check_box, :client_side_validations
|
|
21
|
-
alias_method_chain :radio_button, :client_side_validations
|
|
22
|
-
alias_method_chain :select, :client_side_validations
|
|
23
|
-
alias_method_chain :collection_select, :client_side_validations
|
|
24
|
-
alias_method_chain :grouped_collection_select, :client_side_validations
|
|
25
|
-
alias_method_chain :time_zone_select, :client_side_validations
|
|
26
|
-
|
|
27
|
-
def client_side_form_settings(options, form_helper)
|
|
32
|
+
def client_side_form_settings(_options, form_helper)
|
|
28
33
|
{
|
|
29
|
-
:
|
|
30
|
-
:
|
|
31
|
-
:
|
|
34
|
+
type: self.class.to_s,
|
|
35
|
+
input_tag: form_helper.class.field_error_proc.call(%(<span id="input_tag" />), Struct.new(:error_message, :tag_id).new([], '')),
|
|
36
|
+
label_tag: form_helper.class.field_error_proc.call(%(<label id="label_tag" />), Struct.new(:error_message, :tag_id).new([], ''))
|
|
32
37
|
}
|
|
33
38
|
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
def validate(*attrs)
|
|
41
|
+
options = attrs.pop if attrs.last.is_a?(Hash)
|
|
42
|
+
(attrs.present? ? attrs : @object._validators.keys).each do |attr|
|
|
43
|
+
build_validation_options(attr, validate: options)
|
|
44
|
+
end
|
|
45
|
+
nil
|
|
46
|
+
end
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
def initialize_with_client_side_validations(object_name, object, template, options)
|
|
49
|
+
initialize_without_client_side_validations(object_name, object, template, options)
|
|
50
|
+
@options[:validators] = { object => {} }
|
|
51
|
+
end
|
|
49
52
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
end
|
|
53
|
+
def fields_for_with_client_side_validations(record_name, record_object = nil, fields_options = {}, &block)
|
|
54
|
+
fields_options[:validate] ||= @options[:validate] if @options[:validate] && !fields_options.key?(:validate)
|
|
55
|
+
fields_for_without_client_side_validations(record_name, record_object, fields_options, &block)
|
|
56
|
+
end
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
def check_box_with_client_side_validations(method, options = {}, checked_value = '1', unchecked_value = '0')
|
|
59
|
+
build_validation_options(method, options)
|
|
60
|
+
options.delete(:validate)
|
|
61
|
+
check_box_without_client_side_validations(method, options, checked_value, unchecked_value)
|
|
62
|
+
end
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
def radio_button_with_client_side_validations(method, tag_value, options = {})
|
|
65
|
+
build_validation_options(method, options)
|
|
66
|
+
options.delete(:validate)
|
|
67
|
+
radio_button_without_client_side_validations(method, tag_value, options)
|
|
68
|
+
end
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
def select_with_client_side_validations(method, choices = nil, options = {}, html_options = {}, &block)
|
|
71
|
+
build_validation_options(method, html_options.merge(name: options[:name]))
|
|
72
|
+
html_options.delete(:validate)
|
|
73
|
+
select_without_client_side_validations(method, choices, options, html_options, &block)
|
|
74
|
+
end
|
|
73
75
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
def collection_select_with_client_side_validations(method, collection, value_method, text_method, options = {}, html_options = {})
|
|
77
|
+
build_validation_options(method, html_options.merge(name: options[:name]))
|
|
78
|
+
html_options.delete(:validate)
|
|
79
|
+
collection_select_without_client_side_validations(method, collection, value_method, text_method, options, html_options)
|
|
80
|
+
end
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
def collection_check_boxes_with_client_side_validations(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
|
83
|
+
build_validation_options(method, html_options.merge(name: options[:name]))
|
|
84
|
+
html_options.delete(:validate)
|
|
85
|
+
collection_check_boxes_without_client_side_validations(method, collection, value_method, text_method, options, html_options, &block)
|
|
86
|
+
end
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
def collection_radio_buttons_with_client_side_validations(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
|
89
|
+
build_validation_options(method, html_options.merge(name: options[:name]))
|
|
90
|
+
html_options.delete(:validate)
|
|
91
|
+
collection_radio_buttons_without_client_side_validations(method, collection, value_method, text_method, options, html_options, &block)
|
|
92
|
+
end
|
|
91
93
|
|
|
92
|
-
|
|
94
|
+
def grouped_collection_select_with_client_side_validations(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
|
|
95
|
+
build_validation_options(method, html_options.merge(name: options[:name]))
|
|
96
|
+
html_options.delete(:validate)
|
|
97
|
+
grouped_collection_select_without_client_side_validations(method, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def time_zone_select_with_client_side_validations(method, priority_zones = nil, options = {}, html_options = {})
|
|
101
|
+
build_validation_options(method, html_options.merge(name: options[:name]))
|
|
102
|
+
html_options.delete(:validate)
|
|
103
|
+
time_zone_select_without_client_side_validations(method, priority_zones, options, html_options)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
private
|
|
93
107
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
108
|
+
def build_validation_options(method, options = {})
|
|
109
|
+
return unless @options[:validate]
|
|
110
|
+
|
|
111
|
+
index = @default_options[:index].present? ? "[#{@default_options[:index]}]" : ''
|
|
112
|
+
child_index = @options[:child_index] ? "(\\d+|#{Regexp.escape(@options[:child_index].to_s)})" : '\\d+'
|
|
113
|
+
|
|
114
|
+
name = options[:name] || "#{@object_name}#{index}[#{method}]"
|
|
115
|
+
name = name.to_s.gsub(/_attributes\]\[#{child_index}\]/, '_attributes][]')
|
|
116
|
+
name << '[]' if options[:multiple]
|
|
117
|
+
|
|
118
|
+
@options[:validators][@object][method] = { name: name, options: options[:validate] }
|
|
119
|
+
end
|
|
102
120
|
end
|
|
103
121
|
end
|
|
104
122
|
end
|
|
@@ -1,146 +1,141 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if options[:validate]
|
|
8
|
-
|
|
9
|
-
# Always turn off HTML5 Validations
|
|
10
|
-
options[:html] ||= {}
|
|
11
|
-
options[:html][:novalidate] = 'novalidate'
|
|
12
|
-
|
|
13
|
-
case record
|
|
14
|
-
when String, Symbol
|
|
15
|
-
raise ClientSideValidations::ActionView::Helpers::FormHelper::Error, 'Using form_for(:name, @resource) is not supported with ClientSideValidations. Please use form_for(@resource, :as => :name) instead.'
|
|
16
|
-
else
|
|
17
|
-
object = record.is_a?(Array) ? record.last : record
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
module ClientSideValidations
|
|
3
|
+
module ActionView
|
|
4
|
+
module Helpers
|
|
5
|
+
module FormHelper
|
|
6
|
+
class Error < StandardError
|
|
18
7
|
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
@validators = {}
|
|
22
8
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
build_bound_validators(options)
|
|
27
|
-
options[:id] = html_id if html_id
|
|
28
|
-
script = client_side_form_settings(object, options)
|
|
9
|
+
def form_for(record, options = {}, &block)
|
|
10
|
+
raise ArgumentError, 'Missing block' unless block_given?
|
|
11
|
+
if options[:validate]
|
|
29
12
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
13
|
+
# Always turn off HTML5 Validations
|
|
14
|
+
options[:html] ||= {}
|
|
15
|
+
options[:html][:novalidate] = 'novalidate'
|
|
33
16
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
17
|
+
case record
|
|
18
|
+
when String, Symbol
|
|
19
|
+
raise ClientSideValidations::ActionView::Helpers::FormHelper::Error, 'Using form_for(:name, @resource) is not supported with ClientSideValidations. Please use form_for(@resource, as: :name) instead.'
|
|
20
|
+
else
|
|
21
|
+
object = record.is_a?(Array) ? record.last : record
|
|
22
|
+
object_name = options[:as] || model_name_from_record_or_class(object).param_key
|
|
23
|
+
end
|
|
24
|
+
end
|
|
40
25
|
|
|
41
|
-
|
|
42
|
-
if name && name != true
|
|
43
|
-
content_for(name) { script.html_safe }
|
|
44
|
-
true
|
|
45
|
-
end
|
|
46
|
-
end
|
|
26
|
+
@validators = {}
|
|
47
27
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
28
|
+
# Order matters here. Rails mutates the options object
|
|
29
|
+
html_id = options[:html][:id] if options[:html]
|
|
30
|
+
form = super(record, options, &block)
|
|
31
|
+
options[:id] = html_id if html_id
|
|
52
32
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
output
|
|
57
|
-
end
|
|
33
|
+
build_bound_validators options
|
|
34
|
+
builder = instantiate_builder(object_name, object, options) if object_name && object
|
|
35
|
+
script = client_side_form_settings(object, options, builder)
|
|
58
36
|
|
|
59
|
-
|
|
37
|
+
# Because of the load order requirement above this sub is necessary
|
|
38
|
+
# Would be nice to not do this
|
|
39
|
+
script = insert_validators_into_script(script)
|
|
60
40
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
@validators[key].merge! value
|
|
41
|
+
# rubocop:disable OutputSafety
|
|
42
|
+
# TODO: check if html_safe is really needed here
|
|
43
|
+
if assign_script_to_content_for(options[:validate], script)
|
|
44
|
+
form.html_safe
|
|
66
45
|
else
|
|
67
|
-
|
|
46
|
+
"#{form}#{script}".html_safe
|
|
68
47
|
end
|
|
48
|
+
# rubocop:enable OutputSafety
|
|
69
49
|
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
50
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
script
|
|
82
|
-
end
|
|
51
|
+
def assign_script_to_content_for(name, script)
|
|
52
|
+
# rubocop:disable OutputSafety
|
|
53
|
+
# TODO: check if html_safe is really needed here
|
|
54
|
+
return unless name && name != true
|
|
55
|
+
content_for name, script.html_safe
|
|
56
|
+
true
|
|
57
|
+
# rubocop:enable OutputSafety
|
|
58
|
+
end
|
|
83
59
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
option_hash.merge!(attr[0] => attr[1][:options])
|
|
60
|
+
def apply_form_for_options!(record, object, options)
|
|
61
|
+
super
|
|
62
|
+
options[:html][:validate] = true if options[:validate]
|
|
88
63
|
end
|
|
89
64
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
65
|
+
def fields_for(record_or_name_or_array, record_object = nil, options = {}, &block)
|
|
66
|
+
output = super
|
|
67
|
+
build_bound_validators options
|
|
68
|
+
output
|
|
94
69
|
end
|
|
95
70
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def build_bound_validators(options)
|
|
74
|
+
return unless @validators
|
|
75
|
+
options[:validators].each do |key, value|
|
|
76
|
+
if @validators.key?(key)
|
|
77
|
+
@validators[key].merge! value
|
|
78
|
+
else
|
|
79
|
+
@validators[key] = value
|
|
80
|
+
end
|
|
99
81
|
end
|
|
100
82
|
end
|
|
101
83
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
84
|
+
def insert_validators_into_script(script)
|
|
85
|
+
# There is probably a more performant way of doing this
|
|
86
|
+
# But using String#sub has some issues. Undocumented "features"
|
|
87
|
+
if script
|
|
88
|
+
script = script.split(/"validator_hash"/)
|
|
89
|
+
script = "#{script[0]}#{construct_validators.to_json}#{script[1]}"
|
|
90
|
+
end
|
|
105
91
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
builder = options[:parent_builder]
|
|
92
|
+
script
|
|
93
|
+
end
|
|
109
94
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
var_name = if object.respond_to?(:persisted?) && object.persisted?
|
|
115
|
-
options[:as] ? "edit_#{options[:as]}" : [options[:namespace], dom_id(object, :edit)].compact.join("_")
|
|
116
|
-
else
|
|
117
|
-
options[:as] ? "new_#{options[:as]}" : [options[:namespace], dom_id(object)].compact.join("_")
|
|
95
|
+
def construct_validators
|
|
96
|
+
@validators.each_with_object({}) do |object_opts, validator_hash|
|
|
97
|
+
option_hash = object_opts[1].each_with_object({}) do |attr, result|
|
|
98
|
+
result[attr[0]] = attr[1][:options]
|
|
118
99
|
end
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
100
|
+
|
|
101
|
+
validation_hash =
|
|
102
|
+
if object_opts[0].respond_to?(:client_side_validation_hash)
|
|
103
|
+
object_opts[0].client_side_validation_hash(option_hash)
|
|
104
|
+
else
|
|
105
|
+
{}
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
option_hash.each_key do |attr|
|
|
109
|
+
if validation_hash[attr]
|
|
110
|
+
validator_hash.merge!(object_opts[1][attr][:name] => validation_hash[attr])
|
|
111
|
+
end
|
|
126
112
|
end
|
|
127
113
|
end
|
|
128
114
|
end
|
|
129
115
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
116
|
+
def client_side_form_settings(object, options, builder)
|
|
117
|
+
return unless options[:validate]
|
|
118
|
+
var_name =
|
|
119
|
+
if options[:id]
|
|
120
|
+
options[:id]
|
|
121
|
+
elsif object.respond_to?(:persisted?) && object.persisted?
|
|
122
|
+
options[:as] ? "edit_#{options[:as]}" : [options[:namespace], dom_id(object, :edit)].compact.join('_'.freeze)
|
|
123
|
+
else
|
|
124
|
+
options[:as] ? "new_#{options[:as]}" : [options[:namespace], dom_id(object)].compact.join('_'.freeze)
|
|
125
|
+
end
|
|
136
126
|
|
|
127
|
+
number_format =
|
|
128
|
+
if ClientSideValidations::Config.number_format_with_locale && defined?(I18n)
|
|
129
|
+
I18n.t('number.format').slice(:separator, :delimiter)
|
|
130
|
+
else
|
|
131
|
+
{ separator: '.', delimiter: ',' }
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
patterns = { numericality: "/^(-|\\+)?(?:\\d+|\\d{1,3}(?:\\#{number_format[:delimiter]}\\d{3})+)(?:\\#{number_format[:separator]}\\d*)?$/" }
|
|
137
135
|
|
|
138
|
-
|
|
139
|
-
"//<![CDATA[\nif(window.ClientSideValidations===undefined)window.ClientSideValidations={};window.ClientSideValidations.disabled_validators=#{ClientSideValidations::Config.disabled_validators.to_json};window.ClientSideValidations.number_format=#{number_format.to_json};if(window.ClientSideValidations.patterns===undefined)window.ClientSideValidations.patterns = {};window.ClientSideValidations.patterns.numericality=#{patterns[:numericality]};if(window.ClientSideValidations.remote_validators_prefix===undefined)window.ClientSideValidations.remote_validators_prefix='#{(ClientSideValidations::Config.root_path||"").sub(/\/+\Z/,'')}';if(window.ClientSideValidations.forms===undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['#{var_name}'] = #{builder.client_side_form_settings(options, self).merge(:validators => 'validator_hash').to_json};\n//]]>".html_safe
|
|
136
|
+
javascript_tag "if(window.ClientSideValidations===undefined)window.ClientSideValidations={};window.ClientSideValidations.disabled_validators=#{ClientSideValidations::Config.disabled_validators.to_json};window.ClientSideValidations.number_format=#{number_format.to_json};if(window.ClientSideValidations.patterns===undefined)window.ClientSideValidations.patterns = {};window.ClientSideValidations.patterns.numericality=#{patterns[:numericality]};#{"if(window.ClientSideValidations.remote_validators_prefix===undefined)window.ClientSideValidations.remote_validators_prefix='#{ClientSideValidations::Config.root_path.sub(%r{/+\Z}, '')}';" if ClientSideValidations::Config.root_path.present?}if(window.ClientSideValidations.forms===undefined)window.ClientSideValidations.forms={};window.ClientSideValidations.forms['#{var_name}'] = #{builder.client_side_form_settings(options, self).merge(validators: 'validator_hash').to_json};"
|
|
140
137
|
end
|
|
141
138
|
end
|
|
142
139
|
end
|
|
143
|
-
|
|
144
140
|
end
|
|
145
141
|
end
|
|
146
|
-
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
module ClientSideValidations
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
module ClientSideValidations
|
|
2
|
+
module ActionView
|
|
3
|
+
module Helpers
|
|
4
|
+
module FormTagHelper
|
|
5
|
+
private
|
|
6
|
+
|
|
7
|
+
def html_options_for_form(url_for_options, options)
|
|
8
|
+
options.stringify_keys!
|
|
9
|
+
html_options = {}
|
|
10
|
+
html_options['data-validate'] = options.delete('validate') if options['validate']
|
|
11
|
+
html_options.merge!(super(url_for_options, options))
|
|
12
|
+
end
|
|
9
13
|
end
|
|
14
|
+
end
|
|
10
15
|
end
|
|
11
16
|
end
|
|
12
|
-
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
module ClientSideValidations
|
|
2
|
-
module
|
|
1
|
+
module ClientSideValidations
|
|
2
|
+
module ActionView
|
|
3
|
+
module Helpers
|
|
4
|
+
end
|
|
3
5
|
end
|
|
4
6
|
end
|
|
5
7
|
|
|
@@ -11,4 +13,3 @@ require 'client_side_validations/action_view/form_builder'
|
|
|
11
13
|
ActionView::Base.send(:include, ClientSideValidations::ActionView::Helpers::FormHelper)
|
|
12
14
|
ActionView::Base.send(:include, ClientSideValidations::ActionView::Helpers::FormTagHelper)
|
|
13
15
|
ActionView::Helpers::FormBuilder.send(:include, ClientSideValidations::ActionView::Helpers::FormBuilder)
|
|
14
|
-
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
module ClientSideValidations
|
|
2
|
-
module
|
|
3
|
-
|
|
1
|
+
module ClientSideValidations
|
|
2
|
+
module ActiveModel
|
|
3
|
+
module Acceptance
|
|
4
|
+
private
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
def message_type
|
|
7
|
+
:accepted
|
|
8
|
+
end
|
|
7
9
|
end
|
|
8
10
|
end
|
|
9
11
|
end
|
|
10
|
-
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module ClientSideValidations
|
|
2
|
+
module ActiveModel
|
|
3
|
+
module Conditionals
|
|
4
|
+
private
|
|
5
|
+
|
|
6
|
+
def run_conditionals(conditionals, conditional_type)
|
|
7
|
+
Array.wrap(conditionals).all? do |conditional|
|
|
8
|
+
value = run_one_conditional(conditional)
|
|
9
|
+
if conditional_type == :unless
|
|
10
|
+
!value
|
|
11
|
+
else
|
|
12
|
+
value
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def run_one_conditional(conditional)
|
|
18
|
+
case conditional
|
|
19
|
+
when ::Proc
|
|
20
|
+
case conditional.arity
|
|
21
|
+
when 0
|
|
22
|
+
instance_exec(&conditional)
|
|
23
|
+
when 1
|
|
24
|
+
instance_exec(self, &conditional)
|
|
25
|
+
else
|
|
26
|
+
raise ArgumentError, 'Missing argument'
|
|
27
|
+
end
|
|
28
|
+
when String
|
|
29
|
+
# rubocop:disable Security/Eval'
|
|
30
|
+
l = eval "lambda { |value| #{conditional} }"
|
|
31
|
+
# rubocop:enable Security/Eval'
|
|
32
|
+
instance_exec(nil, &l)
|
|
33
|
+
when Symbol
|
|
34
|
+
send conditional
|
|
35
|
+
else
|
|
36
|
+
raise ArgumentError, "Unknown conditional #{conditional}. If supported by ActiveModel/ActiveRecord open a bug for client_side_validations gem."
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -1,27 +1,7 @@
|
|
|
1
|
-
module ClientSideValidations
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if options[:in].respond_to?(:call)
|
|
6
|
-
if force
|
|
7
|
-
options = self.options.dup
|
|
8
|
-
options[:in] = options[:in].call(model)
|
|
9
|
-
hash = build_client_side_hash(model, attribute, options)
|
|
10
|
-
else
|
|
11
|
-
return
|
|
12
|
-
end
|
|
13
|
-
else
|
|
14
|
-
hash = build_client_side_hash(model, attribute, self.options.dup)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
if hash[:in].is_a?(Range)
|
|
18
|
-
hash[:range] = hash[:in]
|
|
19
|
-
hash.delete(:in)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
hash
|
|
1
|
+
module ClientSideValidations
|
|
2
|
+
module ActiveModel
|
|
3
|
+
module Exclusion
|
|
4
|
+
include EnumerableValidator
|
|
23
5
|
end
|
|
24
|
-
|
|
25
6
|
end
|
|
26
7
|
end
|
|
27
|
-
|