client_side_validations 3.2.2 → 3.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/client_side_validations.gemspec +2 -0
- data/lib/client_side_validations/action_view/form_helper.rb +10 -5
- data/lib/client_side_validations/active_record/middleware.rb +1 -1
- data/lib/client_side_validations/middleware.rb +37 -7
- data/lib/client_side_validations/version.rb +1 -1
- data/vendor/assets/javascripts/rails.validations.js +10 -5
- metadata +37 -46
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 315d850e3c4c93019d3cf6e4052e33e72c3aad67
|
4
|
+
data.tar.gz: 9a3d22a1a8ebd7aba6bbaa93c96cdc848e67927e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4ee962238c0d65d24649fad3aa8cf2cf9369e0c285efe361a3d56ebc5204b8e1d73f8d299e58ebacf97985215b11ca147e64cff1a615523dc4e993a1664198ac
|
7
|
+
data.tar.gz: ec6dddc31912eda921f7c732aa99514b8d5fdce31afa07b4ad1407f5e38b8580314b4c1cb3b45625a776c55cf503292b0be90129da83162e02cb73f63c1b94de
|
@@ -2,7 +2,7 @@ module ClientSideValidations::ActionView::Helpers
|
|
2
2
|
module FormHelper
|
3
3
|
class Error < StandardError; end
|
4
4
|
|
5
|
-
def form_for(record, *args, &
|
5
|
+
def form_for(record, *args, &block)
|
6
6
|
options = args.extract_options!
|
7
7
|
if options[:validate]
|
8
8
|
|
@@ -22,7 +22,8 @@ module ClientSideValidations::ActionView::Helpers
|
|
22
22
|
|
23
23
|
# Order matters here. Rails mutates the options object
|
24
24
|
html_id = options[:html][:id] if options[:html]
|
25
|
-
form = super(record, *(args << options), &
|
25
|
+
form = super(record, *(args << options), &block)
|
26
|
+
build_bound_validators(options)
|
26
27
|
options[:id] = html_id if html_id
|
27
28
|
script = client_side_form_settings(object, options)
|
28
29
|
|
@@ -51,6 +52,13 @@ module ClientSideValidations::ActionView::Helpers
|
|
51
52
|
|
52
53
|
def fields_for(record_or_name_or_array, record_object = nil, options = {}, &block)
|
53
54
|
output = super
|
55
|
+
build_bound_validators(options)
|
56
|
+
output
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def build_bound_validators(options)
|
54
62
|
if @validators
|
55
63
|
options[:validators].each do |key, value|
|
56
64
|
if @validators.key?(key)
|
@@ -60,11 +68,8 @@ module ClientSideValidations::ActionView::Helpers
|
|
60
68
|
end
|
61
69
|
end
|
62
70
|
end
|
63
|
-
output
|
64
71
|
end
|
65
72
|
|
66
|
-
private
|
67
|
-
|
68
73
|
def insert_validators_into_script(script)
|
69
74
|
# There is probably a more performant way of doing this
|
70
75
|
# But using String#sub has some issues. Undocumented "features"
|
@@ -80,11 +80,8 @@ module ClientSideValidations
|
|
80
80
|
|
81
81
|
def is_unique?
|
82
82
|
convert_scope_value_from_null_to_nil
|
83
|
-
|
84
|
-
|
85
|
-
attribute = request.params[resource].keys.first
|
86
|
-
value = request.params[resource][attribute]
|
87
|
-
middleware_class = nil
|
83
|
+
klass, attribute, value = extract_resources
|
84
|
+
middleware_class = nil
|
88
85
|
|
89
86
|
unless Array.wrap(klass._validators[attribute.to_sym]).find { |v| v.kind == :uniqueness }
|
90
87
|
raise NotValidatable
|
@@ -110,11 +107,44 @@ module ClientSideValidations
|
|
110
107
|
end
|
111
108
|
end
|
112
109
|
|
113
|
-
def
|
110
|
+
def extract_resources
|
114
111
|
parent_key = (request.params.keys - IGNORE_PARAMS).first
|
112
|
+
|
113
|
+
if nested?(request.params[parent_key], 1)
|
114
|
+
klass, attribute, value = uproot(request.params[parent_key])
|
115
|
+
klass = klass.classify.constantize
|
116
|
+
else
|
117
|
+
klass = parent_key.classify.constantize
|
118
|
+
attribute = request.params[parent_key].keys.first
|
119
|
+
value = request.params[parent_key][attribute]
|
120
|
+
end
|
121
|
+
|
122
|
+
[klass, attribute, value]
|
123
|
+
end
|
124
|
+
|
125
|
+
def uproot(nested_hash = nil)
|
126
|
+
uproot_helper(nested_hash)[-3..-1]
|
127
|
+
end
|
128
|
+
|
129
|
+
def uproot_helper(nested_hash = nil, keys = [])
|
130
|
+
if nested_hash.respond_to?(:keys)
|
131
|
+
keys << nested_hash.keys.first
|
132
|
+
uproot_helper(nested_hash[nested_hash.keys.first], keys)
|
133
|
+
else
|
134
|
+
keys << nested_hash
|
135
|
+
end
|
115
136
|
end
|
137
|
+
|
138
|
+
def nested?(hash = nil, levels = 0)
|
139
|
+
i = 0
|
140
|
+
until !(hash.respond_to? :keys)
|
141
|
+
hash = hash[hash.keys.first]
|
142
|
+
i += 1
|
143
|
+
end
|
144
|
+
i > levels
|
145
|
+
end
|
146
|
+
|
116
147
|
end
|
117
148
|
end
|
118
|
-
|
119
149
|
end
|
120
150
|
|
@@ -321,6 +321,7 @@
|
|
321
321
|
}
|
322
322
|
return options.messages.numericality;
|
323
323
|
}
|
324
|
+
val = val.replace(new RegExp("\\" + ClientSideValidations.number_format.delimiter, 'g'), "").replace(new RegExp("\\" + ClientSideValidations.number_format.separator, 'g'), ".");
|
324
325
|
if (options.only_integer && !/^[+-]?\d+$/.test(val)) {
|
325
326
|
return options.messages.only_integer;
|
326
327
|
}
|
@@ -344,7 +345,6 @@
|
|
344
345
|
} else {
|
345
346
|
return;
|
346
347
|
}
|
347
|
-
val = val.replace(new RegExp("\\" + ClientSideValidations.number_format.delimiter, 'g'), "").replace(new RegExp("\\" + ClientSideValidations.number_format.separator, 'g'), ".");
|
348
348
|
fn = new Function("return " + val + " " + operator + " " + check_value);
|
349
349
|
if (!fn()) {
|
350
350
|
return options.messages[check];
|
@@ -533,11 +533,8 @@
|
|
533
533
|
name = options['class'] + '[' + name.split('[')[1];
|
534
534
|
}
|
535
535
|
data[name] = element.val();
|
536
|
-
if (ClientSideValidations.remote_validators_prefix == null) {
|
537
|
-
ClientSideValidations.remote_validators_prefix = "";
|
538
|
-
}
|
539
536
|
if (jQuery.ajax({
|
540
|
-
url:
|
537
|
+
url: ClientSideValidations.remote_validators_url_for('uniqueness'),
|
541
538
|
data: data,
|
542
539
|
async: false,
|
543
540
|
cache: false
|
@@ -548,6 +545,14 @@
|
|
548
545
|
}
|
549
546
|
};
|
550
547
|
|
548
|
+
window.ClientSideValidations.remote_validators_url_for = function(validator) {
|
549
|
+
if (ClientSideValidations.remote_validators_prefix != null) {
|
550
|
+
return "//" + window.location.host + "/" + ClientSideValidations.remote_validators_prefix + "/validators/" + validator;
|
551
|
+
} else {
|
552
|
+
return "//" + window.location.host + "/validators/" + validator;
|
553
|
+
}
|
554
|
+
};
|
555
|
+
|
551
556
|
window.ClientSideValidations.disableValidators = function() {
|
552
557
|
var func, validator, _ref, _results;
|
553
558
|
if (window.ClientSideValidations.disabled_validators === void 0) {
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: client_side_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
5
|
-
prerelease:
|
4
|
+
version: 3.2.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brian Cardarella
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-03-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rails
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,55 +27,48 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: sqlite3
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: mocha
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: m
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: sinatra
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ~>
|
84
74
|
- !ruby/object:Gem::Version
|
@@ -86,7 +76,6 @@ dependencies:
|
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - ~>
|
92
81
|
- !ruby/object:Gem::Version
|
@@ -94,81 +83,85 @@ dependencies:
|
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: shotgun
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - '>='
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: thin
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - '>='
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
|
-
- -
|
108
|
+
- - '>='
|
124
109
|
- !ruby/object:Gem::Version
|
125
110
|
version: '0'
|
126
111
|
- !ruby/object:Gem::Dependency
|
127
112
|
name: json
|
128
113
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
114
|
requirements:
|
131
|
-
- -
|
115
|
+
- - '>='
|
132
116
|
- !ruby/object:Gem::Version
|
133
117
|
version: '0'
|
134
118
|
type: :development
|
135
119
|
prerelease: false
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
121
|
requirements:
|
139
|
-
- -
|
122
|
+
- - '>='
|
140
123
|
- !ruby/object:Gem::Version
|
141
124
|
version: '0'
|
142
125
|
- !ruby/object:Gem::Dependency
|
143
126
|
name: coffee-script
|
144
127
|
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
128
|
requirements:
|
147
|
-
- -
|
129
|
+
- - '>='
|
148
130
|
- !ruby/object:Gem::Version
|
149
131
|
version: '0'
|
150
132
|
type: :development
|
151
133
|
prerelease: false
|
152
134
|
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
135
|
requirements:
|
155
|
-
- -
|
136
|
+
- - '>='
|
156
137
|
- !ruby/object:Gem::Version
|
157
138
|
version: '0'
|
158
139
|
- !ruby/object:Gem::Dependency
|
159
140
|
name: jquery-rails
|
160
141
|
requirement: !ruby/object:Gem::Requirement
|
161
|
-
none: false
|
162
142
|
requirements:
|
163
|
-
- -
|
143
|
+
- - '>='
|
164
144
|
- !ruby/object:Gem::Version
|
165
145
|
version: '0'
|
166
146
|
type: :development
|
167
147
|
prerelease: false
|
168
148
|
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
149
|
requirements:
|
171
|
-
- -
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: coveralls
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
172
165
|
- !ruby/object:Gem::Version
|
173
166
|
version: '0'
|
174
167
|
description: Client Side Validations
|
@@ -211,27 +204,25 @@ files:
|
|
211
204
|
- vendor/assets/javascripts/rails.validations.js
|
212
205
|
homepage: https://github.com/bcardarella/client_side_validations
|
213
206
|
licenses: []
|
207
|
+
metadata: {}
|
214
208
|
post_install_message:
|
215
209
|
rdoc_options: []
|
216
210
|
require_paths:
|
217
211
|
- lib
|
218
212
|
required_ruby_version: !ruby/object:Gem::Requirement
|
219
|
-
none: false
|
220
213
|
requirements:
|
221
|
-
- -
|
214
|
+
- - '>='
|
222
215
|
- !ruby/object:Gem::Version
|
223
216
|
version: '0'
|
224
217
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
|
-
none: false
|
226
218
|
requirements:
|
227
|
-
- -
|
219
|
+
- - '>='
|
228
220
|
- !ruby/object:Gem::Version
|
229
221
|
version: '0'
|
230
222
|
requirements: []
|
231
223
|
rubyforge_project:
|
232
|
-
rubygems_version:
|
224
|
+
rubygems_version: 2.0.0
|
233
225
|
signing_key:
|
234
|
-
specification_version:
|
226
|
+
specification_version: 4
|
235
227
|
summary: Client Side Validations
|
236
228
|
test_files: []
|
237
|
-
has_rdoc:
|