client_side_validations 19.1.0 → 20.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +12 -12
- data/lib/client_side_validations/action_view/form_builder.rb +18 -12
- data/lib/client_side_validations/action_view/form_helper.rb +25 -29
- data/lib/client_side_validations/version.rb +1 -1
- data/lib/generators/templates/client_side_validations/initializer.rb +3 -0
- data/vendor/assets/javascripts/rails.validations.js +5 -11
- metadata +9 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 947a8c3e977a52425b7d60ca031c38ba6aa0e22534704859cf10330f42fc7c64
|
4
|
+
data.tar.gz: 120c000d994694b6cf98ceb28ed40507a43e28132563a1d03f43dde3bcf9a272
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82dadc40eac82e9b38fca023d4732a8f6a3d835bc29f5b41ffa68345b8366a797c3a224ac0af0c8f50bc0067361c527741cf43bbf0d07779309134914c80231e
|
7
|
+
data.tar.gz: 125ae43cbb60726874f2ddba6aec7f355ebfb4e5a0e6cf7218cb42b9abb55d100e03f464a835b0b7490bc9232d55f73361cb759a0a3533b758ee0464b87b8717
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 20.0.2 / 2021-12-22
|
4
|
+
|
5
|
+
* [BUGFIX] Fix Rails 7.0 compatibility ([#869](https://github.com/DavyJonesLocker/client_side_validations/issues/869))
|
6
|
+
|
7
|
+
## 20.0.1 / 2021-12-22
|
8
|
+
|
9
|
+
* [BUGFIX] Fix missing HTTP method ([#867](https://github.com/DavyJonesLocker/client_side_validations/issue/867))
|
10
|
+
* [ENHANCEMENT] Update development dependencies
|
11
|
+
|
12
|
+
## 20.0.0 / 2021-12-16
|
13
|
+
|
14
|
+
* [FEATURE] Add Rails 7 compatibility - POSSIBLE BREAKING CHANGE ([#862](https://github.com/DavyJonesLocker/client_side_validations/pull/862))
|
15
|
+
* [ENHANCEMENT] Update development dependencies
|
16
|
+
|
17
|
+
## 19.1.1 / 2021-11-15
|
18
|
+
|
19
|
+
* [ENHANCEMENT] Require MFA to publish gems
|
20
|
+
* [ENHANCEMENT] Update development dependencies
|
21
|
+
|
3
22
|
## 19.1.0 / 2021-10-05
|
4
23
|
|
5
24
|
* [FEATURE] Add Turbo compatibility ([#849](https://github.com/DavyJonesLocker/client_side_validations/pull/849))
|
data/README.md
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/client_side_validations.svg)](https://badge.fury.io/rb/client_side_validations)
|
4
4
|
[![npm version](https://badge.fury.io/js/%40client-side-validations%2Fclient-side-validations.svg)](https://badge.fury.io/js/%40client-side-validations%2Fclient-side-validations)
|
5
|
-
[![
|
6
|
-
[![Build Status](https://github.com/DavyJonesLocker/client_side_validations/actions/workflows/
|
5
|
+
[![Ruby Build Status](https://github.com/DavyJonesLocker/client_side_validations/actions/workflows/ruby.yml/badge.svg)](https://github.com/DavyJonesLocker/client_side_validations/actions)
|
6
|
+
[![JavaScript Build Status](https://github.com/DavyJonesLocker/client_side_validations/actions/workflows/javascript.yml/badge.svg)](https://github.com/DavyJonesLocker/client_side_validations/actions)
|
7
7
|
[![Maintainability](https://api.codeclimate.com/v1/badges/9f9e8bb6edc92615f34e/maintainability)](https://codeclimate.com/github/DavyJonesLocker/client_side_validations/maintainability)
|
8
8
|
[![Coverage Status](https://coveralls.io/repos/github/DavyJonesLocker/client_side_validations/badge.svg?branch=main)](https://coveralls.io/github/DavyJonesLocker/client_side_validations?branch=main)
|
9
9
|
|
10
10
|
|
11
|
-
`ClientSideValidations` made easy for your Rails 5.2 /
|
11
|
+
`ClientSideValidations` made easy for your Rails 5.2 / 6.x / 7.0 applications!
|
12
12
|
|
13
13
|
## Project Goals ##
|
14
14
|
|
@@ -78,17 +78,17 @@ import '@client-side-validations/client-side-validations/src'
|
|
78
78
|
require('@client-side-validations/client-side-validations')
|
79
79
|
```
|
80
80
|
|
81
|
-
##### Heads-up for Turbolinks users #####
|
81
|
+
##### Heads-up for Turbo and Turbolinks users #####
|
82
|
+
|
83
|
+
If you are using [Turbo](https://github.com/hotwired/turbo-rails), use the
|
84
|
+
`import` syntax and make sure that `@client-side-validations/client-side-validations/src`
|
85
|
+
is imported **after** `@hotwired/turbo-rails`, so ClientSideValidations can properly detect
|
86
|
+
`window.Turbo` and attach its event handlers.
|
82
87
|
|
83
88
|
If you are using [Turbolinks](https://github.com/turbolinks/turbolinks) 5.2,
|
84
|
-
use the require syntax and make sure that `@client-side-validations/client-side-validations`
|
85
|
-
is required after`Turbolinks.start()`, so ClientSideValidations can properly
|
86
|
-
attach its event handlers.
|
87
|
-
|
88
|
-
[Turbo](https://github.com/hotwired/turbo-rails) automatically calls `start()`,
|
89
|
-
so you can use the `import` syntax. Just make sure that `@client-side-validations/client-side-validations/src`
|
90
|
-
is imported **after** `turbo`, so ClientSideValidations can properly
|
91
|
-
attach its event handlers.
|
89
|
+
use the `require` syntax and make sure that `@client-side-validations/client-side-validations`
|
90
|
+
is required **after** `Turbolinks.start()`, so ClientSideValidations can properly
|
91
|
+
detect `window.Turbolinks` and attach its event handlers.
|
92
92
|
|
93
93
|
#### When using Sprockets ####
|
94
94
|
|
@@ -22,15 +22,15 @@ module ClientSideValidations
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def initialize(object_name, object, template, options)
|
25
|
-
super
|
25
|
+
super
|
26
26
|
@options[:validators] = { object => {} }
|
27
27
|
end
|
28
28
|
|
29
29
|
def client_side_form_settings(_options, form_helper)
|
30
30
|
{
|
31
31
|
type: self.class.to_s,
|
32
|
-
input_tag: form_helper
|
33
|
-
label_tag: form_helper
|
32
|
+
input_tag: error_field(form_helper, :span, 'input_tag'),
|
33
|
+
label_tag: error_field(form_helper, :label, 'label_tag')
|
34
34
|
}
|
35
35
|
end
|
36
36
|
|
@@ -45,7 +45,7 @@ module ClientSideValidations
|
|
45
45
|
def check_box(method, options = {}, checked_value = '1', unchecked_value = '0')
|
46
46
|
build_validation_options(method, options)
|
47
47
|
options.delete(:validate)
|
48
|
-
super
|
48
|
+
super
|
49
49
|
end
|
50
50
|
|
51
51
|
%i[collection_check_boxes collection_radio_buttons].each do |method_name|
|
@@ -59,7 +59,7 @@ module ClientSideValidations
|
|
59
59
|
def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
|
60
60
|
build_validation_options(method, html_options.merge(name: options[:name]))
|
61
61
|
html_options.delete(:validate)
|
62
|
-
super
|
62
|
+
super
|
63
63
|
end
|
64
64
|
|
65
65
|
def fields_for(record_name, record_object = nil, fields_options = {}, &block)
|
@@ -69,46 +69,52 @@ module ClientSideValidations
|
|
69
69
|
end
|
70
70
|
|
71
71
|
fields_options[:validate] ||= @options[:validate] if @options[:validate] && !fields_options.key?(:validate)
|
72
|
-
super
|
72
|
+
super
|
73
73
|
end
|
74
74
|
|
75
75
|
def fields(scope = nil, model: nil, **options, &block)
|
76
76
|
options[:validate] ||= @options[:validate] if @options[:validate] && !options.key?(:validate)
|
77
|
-
super
|
77
|
+
super
|
78
78
|
end
|
79
79
|
|
80
80
|
def file_field(method, options = {})
|
81
81
|
build_validation_options(method, options)
|
82
82
|
options.delete(:validate)
|
83
|
-
super
|
83
|
+
super
|
84
84
|
end
|
85
85
|
|
86
86
|
def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
|
87
87
|
build_validation_options(method, html_options.merge(name: options[:name]))
|
88
88
|
html_options.delete(:validate)
|
89
|
-
super
|
89
|
+
super
|
90
90
|
end
|
91
91
|
|
92
92
|
def radio_button(method, tag_value, options = {})
|
93
93
|
build_validation_options(method, options)
|
94
94
|
options.delete(:validate)
|
95
|
-
super
|
95
|
+
super
|
96
96
|
end
|
97
97
|
|
98
98
|
def select(method, choices = nil, options = {}, html_options = {}, &block)
|
99
99
|
build_validation_options(method, html_options.merge(name: options[:name]))
|
100
100
|
html_options.delete(:validate)
|
101
|
-
super
|
101
|
+
super
|
102
102
|
end
|
103
103
|
|
104
104
|
def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
|
105
105
|
build_validation_options(method, html_options.merge(name: options[:name]))
|
106
106
|
html_options.delete(:validate)
|
107
|
-
super
|
107
|
+
super
|
108
108
|
end
|
109
109
|
|
110
110
|
private
|
111
111
|
|
112
|
+
def error_field(form_helper, tag, id)
|
113
|
+
form_helper.instance_exec form_helper.content_tag(tag, nil, id: id),
|
114
|
+
Struct.new(:error_message, :tag_id).new([], ''),
|
115
|
+
&form_helper.class.field_error_proc
|
116
|
+
end
|
117
|
+
|
112
118
|
def build_validation_options(method, options = {})
|
113
119
|
return unless @options[:validate]
|
114
120
|
|
@@ -15,35 +15,42 @@ module ClientSideValidations
|
|
15
15
|
# So we basically reimplement the whole form_for method
|
16
16
|
raise ArgumentError, 'Missing block' unless block
|
17
17
|
|
18
|
-
|
18
|
+
options[:html] ||= {}
|
19
19
|
|
20
20
|
# Moving the switch statement to another method to
|
21
21
|
# lower complexity
|
22
|
-
|
22
|
+
model, object_name = check_record(record, options)
|
23
23
|
|
24
|
-
|
24
|
+
remote = options.delete(:remote)
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
output = capture(builder, &block)
|
30
|
-
html_options[:multipart] ||= builder.multipart?
|
26
|
+
if remote && !embed_authenticity_token_in_remote_forms && options[:authenticity_token].blank?
|
27
|
+
options[:authenticity_token] = false
|
28
|
+
end
|
31
29
|
|
32
|
-
|
30
|
+
options[:model] = model
|
31
|
+
options[:scope] = object_name
|
32
|
+
options[:local] = !remote
|
33
|
+
options[:skip_default_ids] = false
|
34
|
+
options[:allow_method_names_outside_object] = options.fetch(:allow_method_names_outside_object, false)
|
33
35
|
|
34
|
-
|
35
|
-
html_options = html_options_for_form(options[:url] || {}, html_options)
|
36
|
-
form_tag_with_body(html_options, output)
|
36
|
+
form_with(**options, &block)
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
40
|
-
super
|
39
|
+
def apply_csv_form_for_options!(record, object, options)
|
41
40
|
options[:html][:validate] = true if options[:validate]
|
41
|
+
options[:html][:method] ||= options[:method]
|
42
|
+
|
43
|
+
if method(:apply_form_for_options!).arity == 2
|
44
|
+
apply_form_for_options! object, options
|
45
|
+
else
|
46
|
+
apply_form_for_options! record, object, options
|
47
|
+
end
|
42
48
|
end
|
43
49
|
|
44
50
|
def fields_for(record_name, record_object = nil, options = {}, &block)
|
45
51
|
# Order matters here. Rails mutates the `options` object
|
46
|
-
|
52
|
+
builder = instantiate_builder(record_name, record_object, options)
|
53
|
+
output = capture(builder, &block)
|
47
54
|
|
48
55
|
build_bound_validators! options
|
49
56
|
|
@@ -61,10 +68,10 @@ module ClientSideValidations
|
|
61
68
|
raise ArgumentError, 'First argument in form cannot contain nil or be empty' unless object
|
62
69
|
|
63
70
|
object_name = options[:as] || model_name_from_record_or_class(object).param_key
|
64
|
-
|
71
|
+
apply_csv_form_for_options!(record, object, options)
|
65
72
|
end
|
66
73
|
|
67
|
-
[
|
74
|
+
[record, object_name]
|
68
75
|
end
|
69
76
|
|
70
77
|
def build_bound_validators!(options)
|
@@ -121,19 +128,8 @@ module ClientSideValidations
|
|
121
128
|
end
|
122
129
|
end
|
123
130
|
|
124
|
-
def apply_html_options!(options, html_options)
|
125
|
-
# Turn off HTML5 validations
|
126
|
-
html_options[:novalidate] = 'novalidate'
|
127
|
-
|
128
|
-
html_options[:data] = options.delete(:data) if options.key?(:data)
|
129
|
-
html_options[:remote] = options.delete(:remote) if options.key?(:remote)
|
130
|
-
html_options[:method] = options.delete(:method) if options.key?(:method)
|
131
|
-
html_options[:enforce_utf8] = options.delete(:enforce_utf8) if options.key?(:enforce_utf8)
|
132
|
-
html_options[:authenticity_token] = options.delete(:authenticity_token)
|
133
|
-
end
|
134
|
-
|
135
131
|
def apply_csv_html_options!(html_options, options, builder)
|
136
|
-
html_options.delete
|
132
|
+
html_options.delete 'validate'
|
137
133
|
|
138
134
|
csv_options = {
|
139
135
|
html_settings: builder.client_side_form_settings(options, self),
|
@@ -9,6 +9,9 @@
|
|
9
9
|
|
10
10
|
# Uncomment the following block if you want each input field to have the validation messages attached.
|
11
11
|
#
|
12
|
+
# Alternatively, for a cleaner approach, it is possible to set
|
13
|
+
# `config.action_view.field_error_proc` in the application configuration
|
14
|
+
#
|
12
15
|
# Note: client_side_validation requires the error to be encapsulated within
|
13
16
|
# <label for="#{instance.send(:tag_id)}" class="message"></label>
|
14
17
|
#
|
@@ -17,17 +17,11 @@
|
|
17
17
|
function _typeof(obj) {
|
18
18
|
"@babel/helpers - typeof";
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
25
|
-
_typeof = function (obj) {
|
26
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
27
|
-
};
|
28
|
-
}
|
29
|
-
|
30
|
-
return _typeof(obj);
|
20
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
21
|
+
return typeof obj;
|
22
|
+
} : function (obj) {
|
23
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
24
|
+
}, _typeof(obj);
|
31
25
|
}
|
32
26
|
|
33
27
|
var ClientSideValidations = {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: client_side_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 20.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geremia Taglialatela
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-12-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
version: '5.2'
|
21
21
|
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: '7.
|
23
|
+
version: '7.1'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
version: '5.2'
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '7.
|
33
|
+
version: '7.1'
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: js_regex
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,22 +133,16 @@ dependencies:
|
|
133
133
|
name: simplecov
|
134
134
|
requirement: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - "
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: 0.18.5
|
139
|
-
- - "<"
|
136
|
+
- - "~>"
|
140
137
|
- !ruby/object:Gem::Version
|
141
|
-
version:
|
138
|
+
version: 0.21.2
|
142
139
|
type: :development
|
143
140
|
prerelease: false
|
144
141
|
version_requirements: !ruby/object:Gem::Requirement
|
145
142
|
requirements:
|
146
|
-
- - "
|
147
|
-
- !ruby/object:Gem::Version
|
148
|
-
version: 0.18.5
|
149
|
-
- - "<"
|
143
|
+
- - "~>"
|
150
144
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
145
|
+
version: 0.21.2
|
152
146
|
- !ruby/object:Gem::Dependency
|
153
147
|
name: simplecov-lcov
|
154
148
|
requirement: !ruby/object:Gem::Requirement
|
@@ -265,6 +259,7 @@ homepage: https://github.com/DavyJonesLocker/client_side_validations
|
|
265
259
|
licenses:
|
266
260
|
- MIT
|
267
261
|
metadata:
|
262
|
+
rubygems_mfa_required: 'true'
|
268
263
|
bug_tracker_uri: https://github.com/DavyJonesLocker/client_side_validations/issues
|
269
264
|
changelog_uri: https://github.com/DavyJonesLocker/client_side_validations/blob/main/CHANGELOG.md
|
270
265
|
source_code_uri: https://github.com/DavyJonesLocker/client_side_validations
|