client_side_validations 4.2.0 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +1 -0
- data/lib/client_side_validations/action_view/form_helper.rb +23 -21
- data/lib/client_side_validations/active_model.rb +7 -10
- data/lib/client_side_validations/active_model/format.rb +6 -12
- data/lib/client_side_validations/active_model/numericality.rb +5 -8
- data/lib/client_side_validations/generators.rb +6 -2
- data/lib/client_side_validations/middleware.rb +3 -3
- data/lib/client_side_validations/version.rb +2 -1
- data/lib/generators/client_side_validations/copy_assets_generator.rb +15 -15
- data/lib/generators/client_side_validations/install_generator.rb +0 -2
- data/vendor/assets/javascripts/rails.validations.js +7 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1365fb3dbcb3cc78e1ff81c55ca7bae68562a36a
|
4
|
+
data.tar.gz: 929f39e3d25915e36ee0857c28cd366d4ed66a3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aa912a26a995bf9863abb7e7b1384c1d071c8301088f7723c9e24b3863b5d8b6f345226874d811c82263ff16f620153155699f9a5ebca7a7331db33256bc801
|
7
|
+
data.tar.gz: 7f63fd221eb2699d19ca1a4cabe5be3598fd76973f314137fdcaea9b76f704de3c2a5379fce95cb28dae2d4b3f7b182243942bc9d5b364f3e45de8d8aae8d390
|
data/HISTORY.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ClientSideValidations
|
2
3
|
module ActionView
|
3
4
|
module Helpers
|
@@ -91,11 +92,12 @@ module ClientSideValidations
|
|
91
92
|
result[attr[0]] = attr[1][:options]
|
92
93
|
end
|
93
94
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
95
|
+
validation_hash =
|
96
|
+
if object_opts[0].respond_to?(:client_side_validation_hash)
|
97
|
+
object_opts[0].client_side_validation_hash(option_hash)
|
98
|
+
else
|
99
|
+
{}
|
100
|
+
end
|
99
101
|
|
100
102
|
option_hash.each_key do |attr|
|
101
103
|
if validation_hash[attr]
|
@@ -107,26 +109,26 @@ module ClientSideValidations
|
|
107
109
|
|
108
110
|
def client_side_form_settings(object, options, builder)
|
109
111
|
return unless options[:validate]
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
112
|
+
var_name =
|
113
|
+
if options[:id]
|
114
|
+
options[:id]
|
115
|
+
elsif object.respond_to?(:persisted?) && object.persisted?
|
116
|
+
options[:as] ? "edit_#{options[:as]}" : [options[:namespace], dom_id(object, :edit)].compact.join('_'.freeze)
|
117
|
+
else
|
118
|
+
options[:as] ? "new_#{options[:as]}" : [options[:namespace], dom_id(object)].compact.join('_'.freeze)
|
119
|
+
end
|
120
|
+
|
121
|
+
number_format =
|
122
|
+
if ClientSideValidations::Config.number_format_with_locale && defined?(I18n)
|
123
|
+
I18n.t('number.format').slice(:separator, :delimiter)
|
124
|
+
else
|
125
|
+
{ separator: '.', delimiter: ',' }
|
126
|
+
end
|
120
127
|
|
121
|
-
if ClientSideValidations::Config.number_format_with_locale && defined?(I18n)
|
122
|
-
number_format = I18n.t('number.format').slice(:separator, :delimiter)
|
123
|
-
else
|
124
|
-
number_format = { separator: '.', delimiter: ',' }
|
125
|
-
end
|
126
128
|
patterns = { numericality: "/^(-|\\+)?(?:\\d+|\\d{1,3}(?:\\#{number_format[:delimiter]}\\d{3})+)(?:\\#{number_format[:separator]}\\d*)?$/" }
|
127
129
|
|
128
130
|
content_tag(:script) do
|
129
|
-
"//<![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='#{
|
131
|
+
"//<![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(%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};\n//]]>".html_safe
|
130
132
|
end
|
131
133
|
end
|
132
134
|
end
|
@@ -28,7 +28,7 @@ module ClientSideValidations
|
|
28
28
|
return attr_hash if [nil, :block].include?(attr[0])
|
29
29
|
|
30
30
|
validator_hash = attr[1].each_with_object(Hash.new { |h, k| h[k] = [] }) do |validator, kind_hash|
|
31
|
-
next unless can_use_for_client_side_validation?(attr[0], validator, force)
|
31
|
+
next nil unless can_use_for_client_side_validation?(attr[0], validator, force)
|
32
32
|
|
33
33
|
client_side_hash = validator.client_side_hash(self, attr[0], extract_force_option(attr[0], force))
|
34
34
|
if client_side_hash
|
@@ -59,7 +59,7 @@ module ClientSideValidations
|
|
59
59
|
return false if validator_turned_off?(attr, validator, force)
|
60
60
|
|
61
61
|
# Yeah yeah, #new_record? is not part of ActiveModel :p
|
62
|
-
result = ((
|
62
|
+
result = ((respond_to?(:new_record?) && validator.options[:on] == (new_record? ? :create : :update)) || validator.options[:on].nil?)
|
63
63
|
result &&= validator.kind != :block
|
64
64
|
|
65
65
|
if validator.options[:if] || validator.options[:unless]
|
@@ -127,17 +127,14 @@ module ClientSideValidations
|
|
127
127
|
module EnumerableValidator
|
128
128
|
def client_side_hash(model, attribute, force = nil)
|
129
129
|
options = self.options.dup
|
130
|
+
|
130
131
|
if options[:in].respond_to?(:call)
|
131
|
-
|
132
|
-
|
133
|
-
hash = build_client_side_hash(model, attribute, options)
|
134
|
-
else
|
135
|
-
return
|
136
|
-
end
|
137
|
-
else
|
138
|
-
hash = build_client_side_hash(model, attribute, options)
|
132
|
+
return unless force
|
133
|
+
options[:in] = options[:in].call(model)
|
139
134
|
end
|
140
135
|
|
136
|
+
hash = build_client_side_hash(model, attribute, options)
|
137
|
+
|
141
138
|
if hash[:in].is_a?(Range)
|
142
139
|
hash[:range] = hash[:in]
|
143
140
|
hash.delete(:in)
|
@@ -4,19 +4,13 @@ module ClientSideValidations
|
|
4
4
|
def client_side_hash(model, attribute, force = nil)
|
5
5
|
options = self.options.dup
|
6
6
|
if options[:with].respond_to?(:call)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
else
|
11
|
-
return
|
12
|
-
end
|
7
|
+
return unless force
|
8
|
+
options[:with] = options[:with].call(model)
|
9
|
+
build_client_side_hash(model, attribute, options)
|
13
10
|
elsif options[:without].respond_to?(:call)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
else
|
18
|
-
return
|
19
|
-
end
|
11
|
+
return unless force
|
12
|
+
options[:without] = options[:without].call(model)
|
13
|
+
build_client_side_hash(model, attribute, options)
|
20
14
|
else
|
21
15
|
super
|
22
16
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module ClientSideValidations
|
2
2
|
module ActiveModel
|
3
3
|
module Numericality
|
4
|
-
|
4
|
+
@@option_map = {}
|
5
5
|
|
6
6
|
def self.included(base)
|
7
|
-
|
7
|
+
@@option_map.merge!(base::CHECKS.keys.inject({}) { |a, e| a.merge!(e => e) })
|
8
8
|
end
|
9
9
|
|
10
10
|
def client_side_hash(model, attribute, force = nil)
|
@@ -18,16 +18,13 @@ module ClientSideValidations
|
|
18
18
|
|
19
19
|
hash[:allow_blank] = true if options[:allow_nil] || options[:allow_blank]
|
20
20
|
|
21
|
-
|
21
|
+
@@option_map.each do |option, message_type|
|
22
22
|
count = options[option]
|
23
23
|
next unless count
|
24
24
|
|
25
25
|
if count.respond_to?(:call)
|
26
|
-
|
27
|
-
|
28
|
-
else
|
29
|
-
next
|
30
|
-
end
|
26
|
+
next unless force
|
27
|
+
count = count.call(model)
|
31
28
|
end
|
32
29
|
|
33
30
|
hash[:messages][option] = model.errors.generate_message(attribute, message_type, options.merge(count: count))
|
@@ -58,8 +58,8 @@ module ClientSideValidations
|
|
58
58
|
end
|
59
59
|
|
60
60
|
class Uniqueness < Base
|
61
|
-
IGNORE_PARAMS = %w(case_sensitive id scope)
|
62
|
-
|
61
|
+
IGNORE_PARAMS = %w(case_sensitive id scope).freeze
|
62
|
+
@@registered_orms = []
|
63
63
|
class NotValidatable < StandardError; end
|
64
64
|
|
65
65
|
def response
|
@@ -83,7 +83,7 @@ module ClientSideValidations
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def self.registered_orms
|
86
|
-
|
86
|
+
@@registered_orms
|
87
87
|
end
|
88
88
|
|
89
89
|
def registered_orms
|
@@ -9,8 +9,6 @@ module ClientSideValidations
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
private
|
13
|
-
|
14
12
|
def self.asset_directory
|
15
13
|
if asset_pipeline_enabled?
|
16
14
|
"app#{Rails.configuration.assets.prefix}/javascripts"
|
@@ -19,16 +17,8 @@ module ClientSideValidations
|
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
22
|
-
def asset_directory
|
23
|
-
CopyAssetsGenerator.asset_directory
|
24
|
-
end
|
25
|
-
|
26
20
|
def self.assets
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def assets
|
31
|
-
CopyAssetsGenerator.assets
|
21
|
+
ClientSideValidations::Generators.assets
|
32
22
|
end
|
33
23
|
|
34
24
|
def self.asset_file_names
|
@@ -40,15 +30,25 @@ module ClientSideValidations
|
|
40
30
|
defined?(Sprockets).present?
|
41
31
|
end
|
42
32
|
|
43
|
-
def asset_pipeline_enabled?
|
44
|
-
self.class.asset_pipeline_enabled?
|
45
|
-
end
|
46
|
-
|
47
33
|
def self.installation_message
|
48
34
|
"Copies #{asset_file_names} to #{asset_directory}"
|
49
35
|
end
|
50
36
|
|
51
37
|
desc installation_message
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def asset_directory
|
42
|
+
CopyAssetsGenerator.asset_directory
|
43
|
+
end
|
44
|
+
|
45
|
+
def assets
|
46
|
+
CopyAssetsGenerator.assets
|
47
|
+
end
|
48
|
+
|
49
|
+
def asset_pipeline_enabled?
|
50
|
+
self.class.asset_pipeline_enabled?
|
51
|
+
end
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -1,3 +1,10 @@
|
|
1
|
+
|
2
|
+
/*!
|
3
|
+
* Client Side Validations - v4.2.1 (https://github.com/DavyJonesLocker/client_side_validations)
|
4
|
+
* Copyright (c) 2016 Brian Cardarella
|
5
|
+
* Licensed under MIT (http://opensource.org/licenses/mit-license.php)
|
6
|
+
*/
|
7
|
+
|
1
8
|
(function() {
|
2
9
|
var $, validateElement, validateForm, validatorsFor,
|
3
10
|
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: client_side_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Cardarella
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -152,14 +152,14 @@ dependencies:
|
|
152
152
|
requirements:
|
153
153
|
- - "~>"
|
154
154
|
- !ruby/object:Gem::Version
|
155
|
-
version:
|
155
|
+
version: 0.36.0
|
156
156
|
type: :development
|
157
157
|
prerelease: false
|
158
158
|
version_requirements: !ruby/object:Gem::Requirement
|
159
159
|
requirements:
|
160
160
|
- - "~>"
|
161
161
|
- !ruby/object:Gem::Version
|
162
|
-
version:
|
162
|
+
version: 0.36.0
|
163
163
|
- !ruby/object:Gem::Dependency
|
164
164
|
name: simplecov
|
165
165
|
requirement: !ruby/object:Gem::Requirement
|