client_side_validations 3.2.8 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +46 -0
  3. data/README.md +540 -0
  4. data/lib/client_side_validations.rb +0 -1
  5. data/lib/client_side_validations/action_view.rb +4 -3
  6. data/lib/client_side_validations/action_view/form_builder.rb +101 -84
  7. data/lib/client_side_validations/action_view/form_helper.rb +99 -110
  8. data/lib/client_side_validations/action_view/form_tag_helper.rb +13 -9
  9. data/lib/client_side_validations/active_model.rb +95 -80
  10. data/lib/client_side_validations/active_model/absence.rb +11 -0
  11. data/lib/client_side_validations/active_model/acceptance.rb +7 -6
  12. data/lib/client_side_validations/active_model/exclusion.rb +4 -24
  13. data/lib/client_side_validations/active_model/format.rb +24 -23
  14. data/lib/client_side_validations/active_model/inclusion.rb +4 -23
  15. data/lib/client_side_validations/active_model/length.rb +15 -15
  16. data/lib/client_side_validations/active_model/numericality.rb +23 -22
  17. data/lib/client_side_validations/active_model/presence.rb +7 -6
  18. data/lib/client_side_validations/active_record.rb +2 -2
  19. data/lib/client_side_validations/active_record/middleware.rb +41 -39
  20. data/lib/client_side_validations/active_record/uniqueness.rb +24 -23
  21. data/lib/client_side_validations/config.rb +1 -1
  22. data/lib/client_side_validations/core_ext/range.rb +1 -2
  23. data/lib/client_side_validations/core_ext/regexp.rb +6 -4
  24. data/lib/client_side_validations/engine.rb +0 -1
  25. data/lib/client_side_validations/generators.rb +2 -3
  26. data/lib/client_side_validations/generators/rails_validations.rb +2 -3
  27. data/lib/client_side_validations/middleware.rb +17 -24
  28. data/lib/client_side_validations/version.rb +1 -1
  29. data/lib/generators/client_side_validations/copy_assets_generator.rb +7 -11
  30. data/lib/generators/client_side_validations/install_generator.rb +0 -2
  31. data/lib/generators/templates/client_side_validations/initializer.rb +1 -2
  32. data/vendor/assets/javascripts/rails.validations.js +26 -20
  33. metadata +173 -48
  34. data/client_side_validations.gemspec +0 -30
@@ -1,3 +1,3 @@
1
1
  module ClientSideValidations
2
- VERSION = '3.2.8'
2
+ VERSION = '4.2.0'.freeze
3
3
  end
@@ -1,13 +1,11 @@
1
1
  module ClientSideValidations
2
2
  module Generators
3
3
  class CopyAssetsGenerator < Rails::Generators::Base
4
-
5
4
  def copy_javascript_asset
6
- if self.class == CopyAssetsGenerator || !asset_pipeline_enabled?
7
- assets.each do |asset|
8
- source_paths << asset[:path]
9
- copy_file asset[:file], "#{asset_directory}/#{asset[:file]}"
10
- end
5
+ return unless self.class == CopyAssetsGenerator || !asset_pipeline_enabled?
6
+ assets.each do |asset|
7
+ source_paths << asset[:path]
8
+ copy_file asset[:file], "#{asset_directory}/#{asset[:file]}"
11
9
  end
12
10
  end
13
11
 
@@ -26,7 +24,7 @@ module ClientSideValidations
26
24
  end
27
25
 
28
26
  def self.assets
29
- Assets
27
+ ASSETS
30
28
  end
31
29
 
32
30
  def assets
@@ -38,9 +36,8 @@ module ClientSideValidations
38
36
  end
39
37
 
40
38
  def self.asset_pipeline_enabled?
41
- if Rails.application
42
- (Rails.configuration.respond_to?(:assets) ? (Rails.configuration.assets || {}) : {})[:enabled]
43
- end
39
+ # Rails 4.1 doesn't provide :enabled in asset configuration, so we look for Sprockets
40
+ defined?(Sprockets).present?
44
41
  end
45
42
 
46
43
  def asset_pipeline_enabled?
@@ -55,4 +52,3 @@ module ClientSideValidations
55
52
  end
56
53
  end
57
54
  end
58
-
@@ -3,7 +3,6 @@ require 'generators/client_side_validations/copy_assets_generator'
3
3
  module ClientSideValidations
4
4
  module Generators
5
5
  class InstallGenerator < CopyAssetsGenerator
6
-
7
6
  def copy_initializer
8
7
  source_paths << File.expand_path('../../templates/client_side_validations', __FILE__)
9
8
  copy_file 'initializer.rb', 'config/initializers/client_side_validations.rb'
@@ -19,4 +18,3 @@ module ClientSideValidations
19
18
  end
20
19
  end
21
20
  end
22
-
@@ -1,6 +1,6 @@
1
1
  # ClientSideValidations Initializer
2
2
 
3
- # Uncomment to disable uniqueness validator, possible security issue
3
+ # Disabled validators. The uniqueness validator is disabled by default for security issues. Enable it on your own responsibility!
4
4
  # ClientSideValidations::Config.disabled_validators = [:uniqueness]
5
5
 
6
6
  # Uncomment to validate number format with current I18n locale
@@ -18,4 +18,3 @@
18
18
  # %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
19
19
  # end
20
20
  # end
21
-
@@ -109,10 +109,12 @@
109
109
  }
110
110
  return valid;
111
111
  };
112
- destroyInputName = element.attr('name').replace(/\[([^\]]*?)\]$/, '[_destroy]');
113
- if ($("input[name='" + destroyInputName + "']").val() === "1") {
114
- passElement();
115
- return afterValidate();
112
+ if (element.attr('name').search(/\[([^\]]*?)\]$/) >= 0) {
113
+ destroyInputName = element.attr('name').replace(/\[([^\]]*?)\]$/, '[_destroy]');
114
+ if ($("input[name='" + destroyInputName + "']").val() === "1") {
115
+ passElement();
116
+ return afterValidate();
117
+ }
116
118
  }
117
119
  if (element.data('changed') === false) {
118
120
  return afterValidate();
@@ -250,9 +252,8 @@
250
252
  return $(this).attr('data-validate', true);
251
253
  }).on(event, binding);
252
254
  }
253
- $input.filter(':checkbox').on('click.ClientSideValidations', function() {
254
- $(this).isValid(form.ClientSideValidations.settings.validators);
255
- return true;
255
+ $input.filter(':checkbox').on('change.ClientSideValidations', function() {
256
+ return $(this).isValid(form.ClientSideValidations.settings.validators);
256
257
  });
257
258
  return $input.filter('[id$=_confirmation]').each(function() {
258
259
  var confirmationElement, element, ref1, results;
@@ -280,9 +281,14 @@
280
281
 
281
282
  window.ClientSideValidations.validators = {
282
283
  all: function() {
283
- return jQuery.extend({}, ClientSideValidations.validators.local, ClientSideValidations.validators.remote);
284
+ return $.extend({}, ClientSideValidations.validators.local, ClientSideValidations.validators.remote);
284
285
  },
285
286
  local: {
287
+ absence: function(element, options) {
288
+ if (!/^\s*$/.test(element.val() || '')) {
289
+ return options.message;
290
+ }
291
+ },
286
292
  presence: function(element, options) {
287
293
  if (/^\s*$/.test(element.val() || '')) {
288
294
  return options.message;
@@ -311,16 +317,16 @@
311
317
  }
312
318
  return message;
313
319
  }
314
- if (options["with"] && !options["with"].test(element.val())) {
320
+ if (options["with"] && !new RegExp(options["with"].source, options["with"].options).test(element.val())) {
315
321
  return options.message;
316
322
  }
317
- if (options.without && options.without.test(element.val())) {
323
+ if (options.without && new RegExp(options.without.source, options.without.options).test(element.val())) {
318
324
  return options.message;
319
325
  }
320
326
  },
321
327
  numericality: function(element, options) {
322
328
  var CHECKS, check, check_value, fn, form, operator, val;
323
- val = jQuery.trim(element.val());
329
+ val = $.trim(element.val());
324
330
  if (!ClientSideValidations.patterns.numericality.test(val)) {
325
331
  if (options.allow_blank === true && this.presence(element, {
326
332
  message: options.messages.numericality
@@ -459,7 +465,7 @@
459
465
  }
460
466
  },
461
467
  confirmation: function(element, options) {
462
- if (element.val() !== jQuery("#" + (element.attr('id')) + "_confirmation").val()) {
468
+ if (element.val() !== $("#" + (element.attr('id')) + "_confirmation").val()) {
463
469
  return options.message;
464
470
  }
465
471
  },
@@ -514,8 +520,8 @@
514
520
  for (key in ref) {
515
521
  scope_value = ref[key];
516
522
  scoped_name = element.attr('name').replace(/\[\w+\]$/, "[" + key + "]");
517
- scoped_element = jQuery("[name='" + scoped_name + "']");
518
- jQuery("[name='" + scoped_name + "']:checkbox").each(function() {
523
+ scoped_element = $("[name='" + scoped_name + "']");
524
+ $("[name='" + scoped_name + "']:checkbox").each(function() {
519
525
  if (this.checked) {
520
526
  return scoped_element = this;
521
527
  }
@@ -541,7 +547,7 @@
541
547
  name = options['class'] + '[' + name.split('[')[1];
542
548
  }
543
549
  data[name] = element.val();
544
- if (jQuery.ajax({
550
+ if ($.ajax({
545
551
  url: ClientSideValidations.remote_validators_url_for('uniqueness'),
546
552
  data: data,
547
553
  async: false,
@@ -585,8 +591,8 @@
585
591
  var form, inputErrorField, label, labelErrorField;
586
592
  form = $(element[0].form);
587
593
  if (element.data('valid') !== false && (form.find("label.message[for='" + (element.attr('id')) + "']")[0] == null)) {
588
- inputErrorField = jQuery(settings.input_tag);
589
- labelErrorField = jQuery(settings.label_tag);
594
+ inputErrorField = $(settings.input_tag);
595
+ labelErrorField = $(settings.label_tag);
590
596
  label = form.find("label[for='" + (element.attr('id')) + "']:not(.message)");
591
597
  if (element.attr('autofocus')) {
592
598
  element.attr('autofocus', false);
@@ -603,8 +609,8 @@
603
609
  remove: function(element, settings) {
604
610
  var errorFieldClass, form, inputErrorField, label, labelErrorField;
605
611
  form = $(element[0].form);
606
- errorFieldClass = jQuery(settings.input_tag).attr('class');
607
- inputErrorField = element.closest("." + (errorFieldClass.replace(" ", ".")));
612
+ errorFieldClass = $(settings.input_tag).attr('class');
613
+ inputErrorField = element.closest("." + (errorFieldClass.replace(/\ /g, ".")));
608
614
  label = form.find("label[for='" + (element.attr('id')) + "']:not(.message)");
609
615
  labelErrorField = label.closest("." + errorFieldClass);
610
616
  if (inputErrorField[0]) {
@@ -640,7 +646,7 @@
640
646
  }
641
647
  };
642
648
 
643
- $(function() {
649
+ $(document).bind((window.Turbolinks ? 'page:change' : 'ready'), function() {
644
650
  ClientSideValidations.disableValidators();
645
651
  return $(ClientSideValidations.selectors.forms).validate();
646
652
  });
metadata CHANGED
@@ -1,169 +1,293 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: client_side_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.8
4
+ version: 4.2.0
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-02-28 00:00:00.000000000 Z
11
+ date: 2016-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 4.3.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 4.3.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: jquery-rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.1.2
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 5.0.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 3.1.2
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 5.0.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: js_regex
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.0'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.9
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
16
66
  requirements:
17
67
  - - "~>"
18
68
  - !ruby/object:Gem::Version
19
- version: 3.2.0
69
+ version: '1.0'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.0.9
73
+ - !ruby/object:Gem::Dependency
74
+ name: appraisal
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '2.1'
20
80
  type: :development
21
81
  prerelease: false
22
82
  version_requirements: !ruby/object:Gem::Requirement
23
83
  requirements:
24
84
  - - "~>"
25
85
  - !ruby/object:Gem::Version
26
- version: 3.2.0
86
+ version: '2.1'
27
87
  - !ruby/object:Gem::Dependency
28
- name: sqlite3
88
+ name: coveralls
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: 0.8.10
94
+ type: :development
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: 0.8.10
101
+ - !ruby/object:Gem::Dependency
102
+ name: m
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '1.4'
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '1.4'
115
+ - !ruby/object:Gem::Dependency
116
+ name: minitest
29
117
  requirement: !ruby/object:Gem::Requirement
30
118
  requirements:
31
119
  - - ">="
32
120
  - !ruby/object:Gem::Version
33
- version: '0'
121
+ version: 4.7.5
122
+ - - "<"
123
+ - !ruby/object:Gem::Version
124
+ version: 6.0.0
34
125
  type: :development
35
126
  prerelease: false
36
127
  version_requirements: !ruby/object:Gem::Requirement
37
128
  requirements:
38
129
  - - ">="
39
130
  - !ruby/object:Gem::Version
40
- version: '0'
131
+ version: 4.7.5
132
+ - - "<"
133
+ - !ruby/object:Gem::Version
134
+ version: 6.0.0
41
135
  - !ruby/object:Gem::Dependency
42
136
  name: mocha
43
137
  requirement: !ruby/object:Gem::Requirement
44
138
  requirements:
45
- - - ">="
139
+ - - "~>"
46
140
  - !ruby/object:Gem::Version
47
- version: '0'
141
+ version: '1.1'
48
142
  type: :development
49
143
  prerelease: false
50
144
  version_requirements: !ruby/object:Gem::Requirement
51
145
  requirements:
52
- - - ">="
146
+ - - "~>"
53
147
  - !ruby/object:Gem::Version
54
- version: '0'
148
+ version: '1.1'
55
149
  - !ruby/object:Gem::Dependency
56
- name: m
150
+ name: rubocop
57
151
  requirement: !ruby/object:Gem::Requirement
58
152
  requirements:
59
- - - ">="
153
+ - - "~>"
60
154
  - !ruby/object:Gem::Version
61
- version: '0'
155
+ version: '0.35'
62
156
  type: :development
63
157
  prerelease: false
64
158
  version_requirements: !ruby/object:Gem::Requirement
65
159
  requirements:
66
- - - ">="
160
+ - - "~>"
67
161
  - !ruby/object:Gem::Version
68
- version: '0'
162
+ version: '0.35'
69
163
  - !ruby/object:Gem::Dependency
70
- name: sinatra
164
+ name: simplecov
71
165
  requirement: !ruby/object:Gem::Requirement
72
166
  requirements:
73
167
  - - "~>"
74
168
  - !ruby/object:Gem::Version
75
- version: '1.0'
169
+ version: 0.11.1
76
170
  type: :development
77
171
  prerelease: false
78
172
  version_requirements: !ruby/object:Gem::Requirement
79
173
  requirements:
80
174
  - - "~>"
81
175
  - !ruby/object:Gem::Version
82
- version: '1.0'
176
+ version: 0.11.1
83
177
  - !ruby/object:Gem::Dependency
84
- name: shotgun
178
+ name: sqlite3
85
179
  requirement: !ruby/object:Gem::Requirement
86
180
  requirements:
87
- - - ">="
181
+ - - "~>"
88
182
  - !ruby/object:Gem::Version
89
- version: '0'
183
+ version: '1.3'
90
184
  type: :development
91
185
  prerelease: false
92
186
  version_requirements: !ruby/object:Gem::Requirement
93
187
  requirements:
94
- - - ">="
188
+ - - "~>"
95
189
  - !ruby/object:Gem::Version
96
- version: '0'
190
+ version: '1.3'
97
191
  - !ruby/object:Gem::Dependency
98
- name: thin
192
+ name: byebug
99
193
  requirement: !ruby/object:Gem::Requirement
100
194
  requirements:
101
- - - ">="
195
+ - - "~>"
102
196
  - !ruby/object:Gem::Version
103
- version: '0'
197
+ version: '8.2'
104
198
  type: :development
105
199
  prerelease: false
106
200
  version_requirements: !ruby/object:Gem::Requirement
107
201
  requirements:
108
- - - ">="
202
+ - - "~>"
109
203
  - !ruby/object:Gem::Version
110
- version: '0'
204
+ version: '8.2'
111
205
  - !ruby/object:Gem::Dependency
112
- name: json
206
+ name: sinatra
113
207
  requirement: !ruby/object:Gem::Requirement
114
208
  requirements:
115
- - - ">="
209
+ - - "~>"
116
210
  - !ruby/object:Gem::Version
117
- version: '0'
211
+ version: '1.4'
118
212
  type: :development
119
213
  prerelease: false
120
214
  version_requirements: !ruby/object:Gem::Requirement
121
215
  requirements:
122
- - - ">="
216
+ - - "~>"
123
217
  - !ruby/object:Gem::Version
124
- version: '0'
218
+ version: '1.4'
125
219
  - !ruby/object:Gem::Dependency
126
- name: coffee-script
220
+ name: shotgun
127
221
  requirement: !ruby/object:Gem::Requirement
128
222
  requirements:
129
- - - ">="
223
+ - - "~>"
130
224
  - !ruby/object:Gem::Version
131
- version: '0'
225
+ version: 0.9.1
132
226
  type: :development
133
227
  prerelease: false
134
228
  version_requirements: !ruby/object:Gem::Requirement
135
229
  requirements:
136
- - - ">="
230
+ - - "~>"
137
231
  - !ruby/object:Gem::Version
138
- version: '0'
232
+ version: 0.9.1
139
233
  - !ruby/object:Gem::Dependency
140
- name: jquery-rails
234
+ name: thin
141
235
  requirement: !ruby/object:Gem::Requirement
142
236
  requirements:
143
- - - ">="
237
+ - - "~>"
144
238
  - !ruby/object:Gem::Version
145
- version: '0'
239
+ version: '1.6'
146
240
  type: :development
147
241
  prerelease: false
148
242
  version_requirements: !ruby/object:Gem::Requirement
149
243
  requirements:
150
- - - ">="
244
+ - - "~>"
245
+ - !ruby/object:Gem::Version
246
+ version: '1.6'
247
+ - !ruby/object:Gem::Dependency
248
+ name: json
249
+ requirement: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - "~>"
252
+ - !ruby/object:Gem::Version
253
+ version: '1.8'
254
+ type: :development
255
+ prerelease: false
256
+ version_requirements: !ruby/object:Gem::Requirement
257
+ requirements:
258
+ - - "~>"
259
+ - !ruby/object:Gem::Version
260
+ version: '1.8'
261
+ - !ruby/object:Gem::Dependency
262
+ name: coffee-script
263
+ requirement: !ruby/object:Gem::Requirement
264
+ requirements:
265
+ - - "~>"
266
+ - !ruby/object:Gem::Version
267
+ version: '2.4'
268
+ type: :development
269
+ prerelease: false
270
+ version_requirements: !ruby/object:Gem::Requirement
271
+ requirements:
272
+ - - "~>"
151
273
  - !ruby/object:Gem::Version
152
- version: '0'
153
- description: Client Side Validations
274
+ version: '2.4'
275
+ description: Client Side Validations made easy for your Rails 4 applications
154
276
  email:
155
277
  - bcardarella@gmail.com
156
278
  executables: []
157
279
  extensions: []
158
280
  extra_rdoc_files: []
159
281
  files:
160
- - client_side_validations.gemspec
282
+ - HISTORY.md
283
+ - README.md
161
284
  - lib/client_side_validations.rb
162
285
  - lib/client_side_validations/action_view.rb
163
286
  - lib/client_side_validations/action_view/form_builder.rb
164
287
  - lib/client_side_validations/action_view/form_helper.rb
165
288
  - lib/client_side_validations/action_view/form_tag_helper.rb
166
289
  - lib/client_side_validations/active_model.rb
290
+ - lib/client_side_validations/active_model/absence.rb
167
291
  - lib/client_side_validations/active_model/acceptance.rb
168
292
  - lib/client_side_validations/active_model/exclusion.rb
169
293
  - lib/client_side_validations/active_model/format.rb
@@ -188,8 +312,9 @@ files:
188
312
  - lib/generators/client_side_validations/install_generator.rb
189
313
  - lib/generators/templates/client_side_validations/initializer.rb
190
314
  - vendor/assets/javascripts/rails.validations.js
191
- homepage: https://github.com/bcardarella/client_side_validations
192
- licenses: []
315
+ homepage: https://github.com/DavyJonesLocker/client_side_validations
316
+ licenses:
317
+ - MIT
193
318
  metadata: {}
194
319
  post_install_message:
195
320
  rdoc_options: []