client_side_validations 16.2.0 → 17.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5320f254fa2dd8fd48006b2489a2a13319afbff7c89015011d93dab5ea4634f2
4
- data.tar.gz: 111dc6f36d987e5cde360d75baa482e658b3e25145530b49c02a661bc47e40b5
3
+ metadata.gz: d4bcd7d9d20f8b13d6cc5537d879d8f3f76835501d977a585898ce69ad6a6392
4
+ data.tar.gz: cb32cc92ff6d52122a7c2990e7c50cf93c4d48fb3a52bfdb51ed5e3cf1c760c2
5
5
  SHA512:
6
- metadata.gz: 7006a5df563bdd1885dcf2c1afd431f25dbf80bf15a96d9e3889f67c5039d634fec9fe5c92ac2d02a3f38a4df1cb34c573971c480702728b61c5be3b493e3a50
7
- data.tar.gz: 8a2288c4e11f543c923ae3a6d76d6c715eea57140ad172916d4bee2b0c960b11cdfdc64436c3df78e2584420a1688b1fed9e371f864fb441d8e7c0027b1285d3
6
+ metadata.gz: ea2cc5dfe1a81c6b25b7e962ea0d639e44f3e76bf392c5ce1df6db68b4658062236ec6814eb7c3d8cf9335a1f9209e4160b0acdd824b8826d1db7a9ecdde7f50
7
+ data.tar.gz: 7ecf8d894db6009a43ffb0d7084cf95e1ddd67b824b170efbf3610b2cd00aca208631159bb9510f68cafd4ca028fdf4ccb36f4c9fcb83cde446f07e21edc35b1
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 17.0.0 / 2020-05-16
4
+
5
+ * [FEATURE] Drop Ruby 2.3 support
6
+ * [FEATURE] Do not require `jquery-rails` gem ([#785](https://github.com/DavyJonesLocker/client_side_validations/pull/785))
7
+ * [FEATURE] Add support for many association validations ([#783](https://github.com/DavyJonesLocker/client_side_validations/pull/783))
8
+ * [BUGFIX] Fix Rails generators ([#786](https://github.com/DavyJonesLocker/client_side_validations/pull/786))
9
+ * [BUGFIX] Do not validate dynamically disabled inputs ([#789](https://github.com/DavyJonesLocker/client_side_validations/pull/789))
10
+ * [BUGFIX] Fix removal of error messages ([#790](https://github.com/DavyJonesLocker/client_side_validations/pull/790))
11
+ * [ENHANCEMENT] Test against jQuery 3.5.1
12
+
3
13
  ## 16.2.0 / 2020-04-10
4
14
 
5
15
  * [FEATURE] Add jQuery 3.5.0 compatibility ([#779](https://github.com/DavyJonesLocker/client_side_validations/pull/779))
data/README.md CHANGED
@@ -2,10 +2,12 @@
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
+ [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=client_side_validations&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=client_side_validations&package-manager=bundler&version-scheme=semver)
5
6
  [![Build Status](https://secure.travis-ci.org/DavyJonesLocker/client_side_validations.svg?branch=master)](https://travis-ci.org/DavyJonesLocker/client_side_validations)
6
7
  [![Maintainability](https://api.codeclimate.com/v1/badges/9f9e8bb6edc92615f34e/maintainability)](https://codeclimate.com/github/DavyJonesLocker/client_side_validations/maintainability)
7
8
  [![Coverage Status](https://coveralls.io/repos/github/DavyJonesLocker/client_side_validations/badge.svg?branch=master)](https://coveralls.io/github/DavyJonesLocker/client_side_validations?branch=master)
8
9
 
10
+
9
11
  `ClientSideValidations` made easy for your Rails 5.x / Rails 6.0 applications!
10
12
 
11
13
  ## Project Goals ##
@@ -90,9 +92,26 @@ attach its event handlers.
90
92
 
91
93
  #### When using Sprockets ####
92
94
 
93
- Make sure that you are requiring jQuery.
95
+ Since ClientSideValidations can also be used via webpacker, it does not require
96
+ by default `jquery-rails` gem.
97
+
98
+ Make sure that `jquery-rails` is part of your bundled gems and `application.js`,
99
+ otherwise add:
100
+
101
+ ```ruby
102
+ gem 'jquery-rails', '~> 4.3'
103
+ ```
104
+
105
+ to your `Gemfile`, run `bundle`, and add
106
+
107
+ ```js
108
+ //= require jquery
109
+ ```
110
+
111
+ to your `app/assets/javascripts/application.js` file.
94
112
 
95
- Add the following to your `app/assets/javascripts/application.js` file.
113
+ Then, add the following to your `app/assets/javascripts/application.js` file
114
+ after `//= require jquery`.
96
115
 
97
116
  ```js
98
117
  //= require rails.validations
@@ -115,11 +134,10 @@ Note: If you run `copy_assets`, you will need to run it again each time you upda
115
134
  The initializer includes a commented out `ActionView::Base.field_error_proc`.
116
135
  Uncomment this to render your error messages inline with the input fields.
117
136
 
118
- I recommend you not use a solution similar to `error_messages_for`. Client
119
- Side Validations is never going to support rendering this type of error
120
- rendering. If you want to maintain consistency between the client side
121
- rendered validation error messages and the server side rendered
122
- validation error messages please use what is in
137
+ I recommend you to not use a solution similar to `error_messages_for`. Client
138
+ Side Validations does not support this type of error rendering. If you want to
139
+ maintain consistency between the client side rendered validation error messages
140
+ and the server side rendered validation error messages please use what is in
123
141
  `config/initializers/client_side_validations.rb`
124
142
 
125
143
  ## Plugins ##
@@ -7,21 +7,25 @@ module ClientSideValidations
7
7
  def self.prepended(base)
8
8
  (base.field_helpers - %i[label check_box radio_button fields_for hidden_field file_field]).each do |selector|
9
9
  base.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
10
- def #{selector}(method, options = {})
11
- build_validation_options(method, options)
12
- options.delete(:validate)
13
-
14
- # Cannot call super here, override the whole method
15
- @template.send( # @template.send(
16
- #{selector.inspect}, # "text_field",
17
- @object_name, # @object_name,
18
- method, # method,
19
- objectify_options(options)) # objectify_options(options))
20
- end
10
+ # Cannot call super here, rewrite all
11
+ def #{selector}(method, options = {}) # def text_field(method, options = {})
12
+ build_validation_options(method, options) # build_validation_options(method, options)
13
+ options.delete(:validate) # options.delete(:validate)
14
+ @template.send( # @template.send(
15
+ #{selector.inspect}, # "text_field",
16
+ @object_name, # @object_name,
17
+ method, # method,
18
+ objectify_options(options)) # objectify_options(options))
19
+ end # end
21
20
  RUBY_EVAL
22
21
  end
23
22
  end
24
23
 
24
+ def initialize(object_name, object, template, options)
25
+ super(object_name, object, template, options)
26
+ @options[:validators] = { object => {} }
27
+ end
28
+
25
29
  def client_side_form_settings(_options, form_helper)
26
30
  {
27
31
  type: self.class.to_s,
@@ -38,9 +42,24 @@ module ClientSideValidations
38
42
  nil
39
43
  end
40
44
 
41
- def initialize(object_name, object, template, options)
42
- super(object_name, object, template, options)
43
- @options[:validators] = { object => {} }
45
+ def check_box(method, options = {}, checked_value = '1', unchecked_value = '0')
46
+ build_validation_options(method, options)
47
+ options.delete(:validate)
48
+ super(method, options, checked_value, unchecked_value)
49
+ end
50
+
51
+ %i[collection_check_boxes collection_radio_buttons].each do |method_name|
52
+ define_method method_name do |method, collection, value_method, text_method, options = {}, html_options = {}, &block|
53
+ build_validation_options(method, html_options.merge(name: options[:name]))
54
+ html_options.delete(:validate)
55
+ super(method, collection, value_method, text_method, options, html_options, &block)
56
+ end
57
+ end
58
+
59
+ def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
60
+ build_validation_options(method, html_options.merge(name: options[:name]))
61
+ html_options.delete(:validate)
62
+ super(method, collection, value_method, text_method, options, html_options)
44
63
  end
45
64
 
46
65
  def fields_for(record_name, record_object = nil, fields_options = {}, &block)
@@ -53,10 +72,16 @@ module ClientSideValidations
53
72
  super(record_name, record_object, fields_options, &block)
54
73
  end
55
74
 
56
- def check_box(method, options = {}, checked_value = '1', unchecked_value = '0')
75
+ def file_field(method, options = {})
57
76
  build_validation_options(method, options)
58
77
  options.delete(:validate)
59
- super(method, options, checked_value, unchecked_value)
78
+ super(method, options)
79
+ end
80
+
81
+ def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
82
+ build_validation_options(method, html_options.merge(name: options[:name]))
83
+ html_options.delete(:validate)
84
+ super(method, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
60
85
  end
61
86
 
62
87
  def radio_button(method, tag_value, options = {})
@@ -71,38 +96,12 @@ module ClientSideValidations
71
96
  super(method, choices, options, html_options, &block)
72
97
  end
73
98
 
74
- def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
75
- build_validation_options(method, html_options.merge(name: options[:name]))
76
- html_options.delete(:validate)
77
- super(method, collection, value_method, text_method, options, html_options)
78
- end
79
-
80
- %i[collection_check_boxes collection_radio_buttons].each do |method_name|
81
- define_method method_name do |method, collection, value_method, text_method, options = {}, html_options = {}, &block|
82
- build_validation_options(method, html_options.merge(name: options[:name]))
83
- html_options.delete(:validate)
84
- super(method, collection, value_method, text_method, options, html_options, &block)
85
- end
86
- end
87
-
88
- def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
89
- build_validation_options(method, html_options.merge(name: options[:name]))
90
- html_options.delete(:validate)
91
- super(method, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
92
- end
93
-
94
99
  def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
95
100
  build_validation_options(method, html_options.merge(name: options[:name]))
96
101
  html_options.delete(:validate)
97
102
  super(method, priority_zones, options, html_options)
98
103
  end
99
104
 
100
- def file_field(method, options = {})
101
- build_validation_options(method, options)
102
- options.delete(:validate)
103
- super(method, options)
104
- end
105
-
106
105
  private
107
106
 
108
107
  def build_validation_options(method, options = {})
@@ -99,12 +99,15 @@ module ClientSideValidations
99
99
  if validation_hash.key?(attr)
100
100
  validator_hash[name] = validation_hash[attr]
101
101
  elsif attr.to_s.ends_with?('_id')
102
- add_validator_with_association validator_hash, validation_hash, name, attr
102
+ association_name = attr.to_s.gsub(/_id\Z/, '').to_sym
103
+ add_validator_with_association validator_hash, validation_hash, name, association_name
104
+ elsif attr.to_s.ends_with?('_ids')
105
+ association_name = attr.to_s.gsub(/_ids\Z/, '').pluralize.to_sym
106
+ add_validator_with_association validator_hash, validation_hash, name, association_name
103
107
  end
104
108
  end
105
109
 
106
- def add_validator_with_association(validator_hash, validation_hash, name, attr)
107
- association_name = attr.to_s.gsub(/_id\Z/, '').to_sym
110
+ def add_validator_with_association(validator_hash, validation_hash, name, association_name)
108
111
  return unless validation_hash.key?(association_name)
109
112
 
110
113
  validator_hash[name] = validation_hash[association_name]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClientSideValidations
4
- VERSION = '16.2.0'
4
+ VERSION = '17.0.0'
5
5
  end
@@ -4,7 +4,7 @@ module ClientSideValidations
4
4
  module Generators
5
5
  class CopyAssetsGenerator < Rails::Generators::Base
6
6
  def copy_javascript_asset
7
- return unless self.class == CopyAssetsGenerator || !asset_pipeline_enabled?
7
+ return unless self.class == CopyAssetsGenerator || copy_assets?
8
8
 
9
9
  assets.each do |asset|
10
10
  source_paths << asset[:path]
@@ -13,7 +13,7 @@ module ClientSideValidations
13
13
  end
14
14
 
15
15
  def self.asset_directory
16
- if asset_pipeline_enabled?
16
+ if sprockets?
17
17
  "app#{Rails.configuration.assets.prefix}/javascripts"
18
18
  else
19
19
  'public/javascripts'
@@ -28,9 +28,16 @@ module ClientSideValidations
28
28
  assets.map { |asset| asset[:file] }.join(', ')
29
29
  end
30
30
 
31
- def self.asset_pipeline_enabled?
32
- # Rails 4.1 doesn't provide :enabled in asset configuration, so we look for Sprockets
33
- defined?(Sprockets).present?
31
+ def self.copy_assets?
32
+ !sprockets? && !webpacker?
33
+ end
34
+
35
+ def self.sprockets?
36
+ defined?(Sprockets)
37
+ end
38
+
39
+ def self.webpacker?
40
+ defined?(Webpacker)
34
41
  end
35
42
 
36
43
  def self.installation_message
@@ -49,8 +56,8 @@ module ClientSideValidations
49
56
  CopyAssetsGenerator.assets
50
57
  end
51
58
 
52
- def asset_pipeline_enabled?
53
- self.class.asset_pipeline_enabled?
59
+ def copy_assets?
60
+ self.class.copy_assets?
54
61
  end
55
62
  end
56
63
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'generators/client_side_validations/copy_assets_generator'
3
+ require_relative 'copy_assets_generator'
4
4
 
5
5
  module ClientSideValidations
6
6
  module Generators
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Client Side Validations JS - v0.1.3 (https://github.com/DavyJonesLocker/client_side_validations)
2
+ * Client Side Validations JS - v0.1.4 (https://github.com/DavyJonesLocker/client_side_validations)
3
3
  * Copyright (c) 2020 Geremia Taglialatela, Brian Cardarella
4
4
  * Licensed under MIT (https://opensource.org/licenses/mit-license.php)
5
5
  */
@@ -194,10 +194,11 @@
194
194
  },
195
195
  remove: function remove(element, settings) {
196
196
  var form = $(element[0].form);
197
- var errorFieldClass = $(settings.input_tag).attr('class');
198
- var inputErrorField = element.closest('.' + errorFieldClass.replace(/ /g, '.'));
197
+ var inputErrorFieldClass = $(settings.input_tag).attr('class');
198
+ var inputErrorField = element.closest('.' + inputErrorFieldClass.replace(/ /g, '.'));
199
199
  var label = form.find("label[for='" + element.attr('id') + "']:not(.message)");
200
- var labelErrorField = label.closest('.' + errorFieldClass);
200
+ var labelErrorFieldClass = $(settings.label_tag).attr('class');
201
+ var labelErrorField = label.closest('.' + labelErrorFieldClass.replace(/ /g, '.'));
201
202
 
202
203
  if (inputErrorField[0]) {
203
204
  inputErrorField.find('#' + element.attr('id')).detach();
@@ -726,7 +727,7 @@
726
727
  };
727
728
 
728
729
  var executeAllValidators = function executeAllValidators(element, validators) {
729
- if (element.data('changed') === false) {
730
+ if (element.data('changed') === false || element.prop('disabled')) {
730
731
  return;
731
732
  }
732
733
 
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: 16.2.0
4
+ version: 17.0.0
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: 2020-04-11 00:00:00.000000000 Z
12
+ date: 2020-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -31,20 +31,6 @@ dependencies:
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '6.1'
34
- - !ruby/object:Gem::Dependency
35
- name: jquery-rails
36
- requirement: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '4.3'
41
- type: :runtime
42
- prerelease: false
43
- version_requirements: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '4.3'
48
34
  - !ruby/object:Gem::Dependency
49
35
  name: js_regex
50
36
  requirement: !ruby/object:Gem::Requirement
@@ -77,42 +63,30 @@ dependencies:
77
63
  name: byebug
78
64
  requirement: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '10.0'
83
- - - "<"
66
+ - - "~>"
84
67
  - !ruby/object:Gem::Version
85
- version: '12'
68
+ version: '11.1'
86
69
  type: :development
87
70
  prerelease: false
88
71
  version_requirements: !ruby/object:Gem::Requirement
89
72
  requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: '10.0'
93
- - - "<"
73
+ - - "~>"
94
74
  - !ruby/object:Gem::Version
95
- version: '12'
75
+ version: '11.1'
96
76
  - !ruby/object:Gem::Dependency
97
77
  name: coveralls_reborn
98
78
  requirement: !ruby/object:Gem::Requirement
99
79
  requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: 0.14.0
103
- - - "<"
80
+ - - "~>"
104
81
  - !ruby/object:Gem::Version
105
- version: '0.16'
82
+ version: 0.16.0
106
83
  type: :development
107
84
  prerelease: false
108
85
  version_requirements: !ruby/object:Gem::Requirement
109
86
  requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: 0.14.0
113
- - - "<"
87
+ - - "~>"
114
88
  - !ruby/object:Gem::Version
115
- version: '0.16'
89
+ version: 0.16.0
116
90
  - !ruby/object:Gem::Dependency
117
91
  name: m
118
92
  requirement: !ruby/object:Gem::Requirement
@@ -175,14 +149,14 @@ dependencies:
175
149
  requirements:
176
150
  - - "~>"
177
151
  - !ruby/object:Gem::Version
178
- version: 0.81.0
152
+ version: 0.83.0
179
153
  type: :development
180
154
  prerelease: false
181
155
  version_requirements: !ruby/object:Gem::Requirement
182
156
  requirements:
183
157
  - - "~>"
184
158
  - !ruby/object:Gem::Version
185
- version: 0.81.0
159
+ version: 0.83.0
186
160
  - !ruby/object:Gem::Dependency
187
161
  name: rubocop-performance
188
162
  requirement: !ruby/object:Gem::Requirement
@@ -215,22 +189,16 @@ dependencies:
215
189
  name: simplecov
216
190
  requirement: !ruby/object:Gem::Requirement
217
191
  requirements:
218
- - - ">="
219
- - !ruby/object:Gem::Version
220
- version: 0.17.1
221
- - - "<"
192
+ - - "~>"
222
193
  - !ruby/object:Gem::Version
223
- version: '0.19'
194
+ version: 0.18.5
224
195
  type: :development
225
196
  prerelease: false
226
197
  version_requirements: !ruby/object:Gem::Requirement
227
198
  requirements:
228
- - - ">="
229
- - !ruby/object:Gem::Version
230
- version: 0.17.1
231
- - - "<"
199
+ - - "~>"
232
200
  - !ruby/object:Gem::Version
233
- version: '0.19'
201
+ version: 0.18.5
234
202
  - !ruby/object:Gem::Dependency
235
203
  name: sqlite3
236
204
  requirement: !ruby/object:Gem::Requirement
@@ -344,7 +312,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
344
312
  requirements:
345
313
  - - "~>"
346
314
  - !ruby/object:Gem::Version
347
- version: '2.3'
315
+ version: '2.4'
348
316
  required_rubygems_version: !ruby/object:Gem::Requirement
349
317
  requirements:
350
318
  - - ">="