client_side_validations 23.1.0 → 25.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +105 -65
- data/lib/client_side_validations/action_view/form_helper.rb +1 -1
- data/lib/client_side_validations/version.rb +1 -1
- data/vendor/assets/javascripts/rails.validations.js +621 -689
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6ab5824b9451df03da349f928c023f781eeaaf4f4fcad4b1f764b5ac1c27c4ad
|
|
4
|
+
data.tar.gz: c1b76dad75ed9533d4ab10f07899b1b3cfb17323619bc1d4b77acfd38da6817f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5b71dda7c76df4b2b9a17f22a643da7cb8697c3a61265f39484f9ef86ba5de08afe04ab668dd4764e4ac16b8155036793146484c88e699399b4bbb11074fec39
|
|
7
|
+
data.tar.gz: 7b022b94f2d08082825437cd2616c641cc22ff20a42c6d0f0e7b3c72400cf948c75fd5482c6384785e0e330f0ebedfb837ab762a71da9c20028f42237a4dc5fd
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 25.0.0 / 2026-07-05
|
|
4
|
+
|
|
5
|
+
* [FEATURE] Breaking change: Remove unused JavaScript source exports
|
|
6
|
+
- Deep imports of `src/validators/local/*` must use named exports instead of the removed default object exports, for example `import { acceptanceLocalValidator } from '@client-side-validations/client-side-validations/src/validators/local/acceptance'`
|
|
7
|
+
- Remove the unused `addClass` and `removeClass` exports from `src/utils.js`
|
|
8
|
+
- Explicitly remove dead \`inputs\` and \`validate_inputs\` entries from \`ClientSideValidations.selectors\`; only \`forms\` is read by the runtime
|
|
9
|
+
* [FEATURE] Breaking change: Replace Rollup with Rolldown v1 for bundling (10–30× faster builds)
|
|
10
|
+
* [FEATURE] Breaking change: Replace ESLint + neostandard with Oxlint v1 for linting (50–100× faster)
|
|
11
|
+
* [FEATURE] Breaking change: Drop Babel — transpilation handled by Rolldown's built-in Oxc transforms (minimum browser targets are unchanged: Chrome 60+, Firefox 60+, iOS 12+, Safari 12+)
|
|
12
|
+
* [ENHANCEMENT] Remove 9 unused npm devDependencies (smaller install footprint)
|
|
13
|
+
|
|
14
|
+
## 24.0.0 / 2026-04-19
|
|
15
|
+
* [FEATURE] Breaking change: Remove the jQuery runtime dependency and the old jQuery plugin aliases from the published JavaScript assets
|
|
16
|
+
* [FEATURE] Breaking change: Public JavaScript APIs now work with native DOM elements and DOM collections instead of jQuery-wrapped objects
|
|
17
|
+
* [ENHANCEMENT] Use native browser events and event listeners throughout the runtime and test harness
|
|
18
|
+
|
|
3
19
|
## 23.1.0 / 2026-01-27
|
|
4
20
|
|
|
5
21
|
* [FEATURE] Add jQuery 4.0.0 compatibility
|
data/README.md
CHANGED
|
@@ -56,12 +56,11 @@ config/initializers/client_side_validations.rb
|
|
|
56
56
|
|
|
57
57
|
Instructions depend on your technology stack.
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
ClientSideValidations no longer depends on jQuery.
|
|
60
|
+
If you previously installed `jquery-rails`, `jquery_ujs`, or custom jQuery startup code only for ClientSideValidations, you can remove that integration when upgrading to 24.x.
|
|
60
61
|
|
|
61
62
|
#### When using Webpacker ####
|
|
62
63
|
|
|
63
|
-
Make sure that you are requiring jQuery.
|
|
64
|
-
|
|
65
64
|
Add the following package:
|
|
66
65
|
|
|
67
66
|
```sh
|
|
@@ -72,7 +71,7 @@ Then add the following line to your `app/javascript/packs/application.js` pack:
|
|
|
72
71
|
|
|
73
72
|
```js
|
|
74
73
|
// If you are using `import` syntax
|
|
75
|
-
import '@client-side-validations/client-side-validations
|
|
74
|
+
import '@client-side-validations/client-side-validations'
|
|
76
75
|
|
|
77
76
|
// If you are using `require` syntax
|
|
78
77
|
require('@client-side-validations/client-side-validations')
|
|
@@ -81,7 +80,7 @@ require('@client-side-validations/client-side-validations')
|
|
|
81
80
|
##### Heads-up for Turbo and Turbolinks users #####
|
|
82
81
|
|
|
83
82
|
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
|
|
83
|
+
`import` syntax and make sure that `@client-side-validations/client-side-validations`
|
|
85
84
|
is imported **after** `@hotwired/turbo-rails`, so ClientSideValidations can properly detect
|
|
86
85
|
`window.Turbo` and attach its event handlers.
|
|
87
86
|
|
|
@@ -92,42 +91,77 @@ detect `window.Turbolinks` and attach its event handlers.
|
|
|
92
91
|
|
|
93
92
|
#### When using Sprockets ####
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
by default `jquery-rails` gem.
|
|
94
|
+
Add the following to your `app/assets/javascripts/application.js` file:
|
|
97
95
|
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
```js
|
|
97
|
+
//= require rails.validations
|
|
98
|
+
```
|
|
100
99
|
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
If you are using [Turbolinks](https://github.com/turbolinks/turbolinks),
|
|
101
|
+
make sure that `rails.validations` is required **after** `turbolinks`, so
|
|
102
|
+
ClientSideValidations can properly attach its event handlers.
|
|
103
|
+
|
|
104
|
+
If you need to copy the asset files from the gem into your project, run:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
rails g client_side_validations:copy_assets
|
|
103
108
|
```
|
|
104
109
|
|
|
105
|
-
|
|
110
|
+
Note: If you run `copy_assets`, you will need to run it again each time you update this project.
|
|
111
|
+
|
|
112
|
+
## Migration Guide ##
|
|
113
|
+
|
|
114
|
+
### 24.x Breaking Changes ###
|
|
115
|
+
|
|
116
|
+
If you are upgrading to 24.x, update your integration code to use the `ClientSideValidations` object directly.
|
|
117
|
+
|
|
118
|
+
The old jQuery plugin methods are removed. Use the DOM-first public API instead:
|
|
106
119
|
|
|
107
120
|
```js
|
|
108
|
-
|
|
121
|
+
ClientSideValidations.enable(form)
|
|
122
|
+
ClientSideValidations.validate(form)
|
|
123
|
+
ClientSideValidations.isValid(form, validators)
|
|
124
|
+
ClientSideValidations.disable(form)
|
|
125
|
+
ClientSideValidations.reset(form)
|
|
109
126
|
```
|
|
110
127
|
|
|
111
|
-
|
|
128
|
+
These methods accept native DOM elements and DOM collections. They do not accept jQuery objects or CSS selector strings.
|
|
112
129
|
|
|
113
|
-
|
|
114
|
-
|
|
130
|
+
Custom validators, form builders, and callbacks now receive native DOM nodes instead of jQuery wrappers. Update any custom code to use DOM APIs such as `.value`, `.form`, `.closest()`, and `querySelector()`.
|
|
131
|
+
Local validators are called as `(element, options)`. Form callbacks receive `(form, eventData)`, and element callbacks receive either `(element, message, callback)` or `(element, callback)` depending on the event.
|
|
115
132
|
|
|
116
|
-
|
|
117
|
-
|
|
133
|
+
All runtime-owned validation state attributes are now namespaced under `csv`. If you read or write these attributes in custom selectors, callbacks, or validators, update them to the scoped names:
|
|
134
|
+
|
|
135
|
+
```text
|
|
136
|
+
data-changed => data-csv-changed
|
|
137
|
+
data-valid => data-csv-valid
|
|
138
|
+
data-validate => data-csv-validate
|
|
139
|
+
data-not-locally-unique => data-csv-not-locally-unique
|
|
118
140
|
```
|
|
119
141
|
|
|
120
|
-
|
|
121
|
-
make sure that `rails.validations` is required **after** `turbolinks`, so
|
|
122
|
-
ClientSideValidations can properly attach its event handlers.
|
|
142
|
+
The matching dataset properties are `element.dataset.csvChanged`, `element.dataset.csvValid`, `element.dataset.csvValidate`, and `element.dataset.csvNotLocallyUnique`. `csvChanged` is stored as the string values `'true'` and `'false'`.
|
|
123
143
|
|
|
124
|
-
|
|
144
|
+
**jQuery namespaced events are removed.** Events are now plain native DOM custom events. If your application listens to or unbinds events using jQuery-style namespacing, you must update those calls.
|
|
145
|
+
|
|
146
|
+
Before:
|
|
125
147
|
|
|
148
|
+
```js
|
|
149
|
+
$(form).on('form:validate:before.ClientSideValidations', handler)
|
|
150
|
+
$(input).off('.ClientSideValidations')
|
|
126
151
|
```
|
|
127
|
-
|
|
152
|
+
|
|
153
|
+
After:
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
form.addEventListener('form:validate:before', handler)
|
|
157
|
+
// store and pass the handler reference to removeEventListener when unbinding
|
|
128
158
|
```
|
|
129
159
|
|
|
130
|
-
|
|
160
|
+
The full list of native events dispatched by ClientSideValidations: `form:validate:before`, `form:validate:after`, `form:validate:pass`, `form:validate:fail`, `element:validate:before`, `element:validate:after`, `element:validate:pass`, `element:validate:fail`.
|
|
161
|
+
|
|
162
|
+
If you are upgrading from a version older than 23.0.0, the `data-csv-*` renaming above is required for any custom code that still reads or writes the old attribute names. If you are already on 23.x, the new 24.x upgrade step is to update any local uniqueness integrations that still reference `data-not-locally-unique` or `element.dataset.notLocallyUnique`.
|
|
163
|
+
|
|
164
|
+
If your application vendors the compiled asset with `rails g client_side_validations:copy_assets`, run that generator again after upgrading so your copied asset matches the current jQuery-free bundle.
|
|
131
165
|
|
|
132
166
|
## Initializer ##
|
|
133
167
|
|
|
@@ -324,11 +358,11 @@ If you need to change the markup of how the errors are rendered you can modify t
|
|
|
324
358
|
|
|
325
359
|
```js
|
|
326
360
|
window.ClientSideValidations.formBuilders['ActionView::Helpers::FormBuilder'] = {
|
|
327
|
-
add: function(
|
|
361
|
+
add: function(element, settings, message) {
|
|
328
362
|
// custom add code here
|
|
329
363
|
},
|
|
330
364
|
|
|
331
|
-
remove: function(
|
|
365
|
+
remove: function(element, settings) {
|
|
332
366
|
// custom remove code here
|
|
333
367
|
}
|
|
334
368
|
}
|
|
@@ -376,14 +410,14 @@ en:
|
|
|
376
410
|
Finally we need to add a client side validator. This can be done by hooking into the `ClientSideValidations.validator` object. Create a new file `app/assets/javascripts/rails.validations.customValidators.js`
|
|
377
411
|
|
|
378
412
|
```js
|
|
379
|
-
// The
|
|
380
|
-
// The
|
|
381
|
-
window.ClientSideValidations.validators.local
|
|
413
|
+
// The options variable is a JSON Object
|
|
414
|
+
// The element variable is a DOM element
|
|
415
|
+
window.ClientSideValidations.validators.local.email = function (element, options) {
|
|
382
416
|
// Your validator code goes in here
|
|
383
|
-
if (!/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i.test(
|
|
417
|
+
if (!/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i.test(element.value)) {
|
|
384
418
|
// When the value fails to pass validation you need to return the error message.
|
|
385
419
|
// It can be derived from validator.message
|
|
386
|
-
return options.message
|
|
420
|
+
return options.message
|
|
387
421
|
}
|
|
388
422
|
}
|
|
389
423
|
```
|
|
@@ -408,7 +442,7 @@ There are many reasons why you might want to enable, disable, or even completely
|
|
|
408
442
|
If you have rendered a new form via AJAX into your page you will need to enable that form for validation:
|
|
409
443
|
|
|
410
444
|
```js
|
|
411
|
-
|
|
445
|
+
ClientSideValidations.enable(newForm)
|
|
412
446
|
```
|
|
413
447
|
|
|
414
448
|
You should attach this to an event that is fired when the new HTML renders.
|
|
@@ -416,7 +450,7 @@ You should attach this to an event that is fired when the new HTML renders.
|
|
|
416
450
|
You can use the same function if you introduce new inputs to an existing form:
|
|
417
451
|
|
|
418
452
|
```js
|
|
419
|
-
|
|
453
|
+
ClientSideValidations.enable(newInput)
|
|
420
454
|
```
|
|
421
455
|
|
|
422
456
|
### Disabling ###
|
|
@@ -424,7 +458,7 @@ $(new_input).enableClientSideValidations();
|
|
|
424
458
|
If you wish to turn off validations entirely on a form:
|
|
425
459
|
|
|
426
460
|
```js
|
|
427
|
-
|
|
461
|
+
ClientSideValidations.disable(form)
|
|
428
462
|
```
|
|
429
463
|
|
|
430
464
|
### Resetting ###
|
|
@@ -432,44 +466,54 @@ $(form).disableClientSideValidations();
|
|
|
432
466
|
You can reset the current state of the validations, clear all error messages, and reattach clean event handlers:
|
|
433
467
|
|
|
434
468
|
```js
|
|
435
|
-
|
|
469
|
+
ClientSideValidations.reset(form)
|
|
436
470
|
```
|
|
437
471
|
|
|
438
472
|
## Callbacks ##
|
|
439
473
|
|
|
440
474
|
`ClientSideValidations` will run callbacks based upon the state of the element or form. The following callbacks are supported:
|
|
441
475
|
|
|
442
|
-
* `ClientSideValidations.callbacks.element.after(
|
|
443
|
-
* `ClientSideValidations.callbacks.element.before(
|
|
444
|
-
* `ClientSideValidations.callbacks.element.fail(
|
|
445
|
-
* `ClientSideValidations.callbacks.element.pass(
|
|
446
|
-
* `ClientSideValidations.callbacks.form.after(
|
|
447
|
-
* `ClientSideValidations.callbacks.form.before(
|
|
448
|
-
* `ClientSideValidations.callbacks.form.fail(
|
|
449
|
-
* `ClientSideValidations.callbacks.form.pass(
|
|
476
|
+
* `ClientSideValidations.callbacks.element.after(element, eventData)`
|
|
477
|
+
* `ClientSideValidations.callbacks.element.before(element, eventData)`
|
|
478
|
+
* `ClientSideValidations.callbacks.element.fail(element, message, callback, eventData)`
|
|
479
|
+
* `ClientSideValidations.callbacks.element.pass(element, callback, eventData)`
|
|
480
|
+
* `ClientSideValidations.callbacks.form.after(form, eventData)`
|
|
481
|
+
* `ClientSideValidations.callbacks.form.before(form, eventData)`
|
|
482
|
+
* `ClientSideValidations.callbacks.form.fail(form, eventData)`
|
|
483
|
+
* `ClientSideValidations.callbacks.form.pass(form, eventData)`
|
|
450
484
|
|
|
451
485
|
The names of the callbacks should be pretty straight forward. For example, `ClientSideValidations.callbacks.form.fail` will be called if a form failed to validate. And `ClientSideValidations.callbacks.element.before` will be called before that particular element's validations are run.
|
|
452
486
|
|
|
453
|
-
All element callbacks
|
|
487
|
+
All element callbacks receive the DOM element as the first parameter and the native event object as the second parameter. `ClientSideValidations.callbacks.element.fail()` receives the failed message as the second parameter, the callback for adding error fields as the third parameter, and the eventData object as the fourth parameter. `ClientSideValidations.callbacks.element.pass()` receives the callback for removing the error fields as the second parameter. The error field callbacks must still be invoked by your custom callback.
|
|
454
488
|
|
|
455
|
-
All form callbacks
|
|
489
|
+
All form callbacks receive the DOM form element as the first parameter and the native event object as the second parameter.
|
|
456
490
|
|
|
457
|
-
Here is an example callback
|
|
491
|
+
Here is an example callback that animates the error message when validation fails:
|
|
458
492
|
|
|
459
493
|
``` javascript
|
|
460
|
-
|
|
461
|
-
window.ClientSideValidations.callbacks.element.fail = function($element, message, callback) {
|
|
494
|
+
window.ClientSideValidations.callbacks.element.fail = function (element, message, callback) {
|
|
462
495
|
callback()
|
|
463
496
|
|
|
464
|
-
|
|
465
|
-
|
|
497
|
+
var messageElement = element.parentElement.querySelector('.message')
|
|
498
|
+
|
|
499
|
+
if (messageElement) {
|
|
500
|
+
if (typeof messageElement.animate === 'function') {
|
|
501
|
+
messageElement.animate(
|
|
502
|
+
[
|
|
503
|
+
{ opacity: 0, transform: 'translateX(-8px)' },
|
|
504
|
+
{ opacity: 1, transform: 'translateX(0)' }
|
|
505
|
+
],
|
|
506
|
+
{ duration: 250, easing: 'ease-out', fill: 'both' }
|
|
507
|
+
)
|
|
508
|
+
} else {
|
|
509
|
+
messageElement.style.opacity = '1'
|
|
510
|
+
messageElement.style.transform = 'translateX(0)'
|
|
511
|
+
}
|
|
466
512
|
}
|
|
467
513
|
}
|
|
468
514
|
|
|
469
|
-
window.ClientSideValidations.callbacks.element.pass = function(
|
|
470
|
-
|
|
471
|
-
// method so it is run after the animation is complete.
|
|
472
|
-
$element.parent().find('.message').hide('slide', { direction: 'left' }, 500, callback)
|
|
515
|
+
window.ClientSideValidations.callbacks.element.pass = function (element, callback) {
|
|
516
|
+
callback()
|
|
473
517
|
}
|
|
474
518
|
```
|
|
475
519
|
|
|
@@ -478,12 +522,9 @@ window.ClientSideValidations.callbacks.element.pass = function($element, callbac
|
|
|
478
522
|
background-color: red;
|
|
479
523
|
border-bottom-right-radius: 5px 5px;
|
|
480
524
|
border-top-right-radius: 5px 5px;
|
|
525
|
+
display: inline-block;
|
|
481
526
|
padding: 2px 5px;
|
|
482
527
|
}
|
|
483
|
-
|
|
484
|
-
div.field_with_errors div.ui-effects-wrapper {
|
|
485
|
-
display: inline-block !important;
|
|
486
|
-
}
|
|
487
528
|
```
|
|
488
529
|
|
|
489
530
|
Finally uncomment the `ActionView::Base.field_error_proc` override in `config/initializers/client_side_validations.rb`
|
|
@@ -506,22 +547,21 @@ By default, ClientSideValidations will automatically validate the form.
|
|
|
506
547
|
If for some reason you would like to manually validate the form (for example you're working with a multi-step form), you can use the following approach:
|
|
507
548
|
|
|
508
549
|
```js
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
validators =
|
|
550
|
+
const input = document.getElementById('myInputField')
|
|
551
|
+
const form = input.form
|
|
552
|
+
const validators = form.ClientSideValidations.settings.validators
|
|
512
553
|
|
|
513
554
|
// Validate a single field
|
|
514
|
-
|
|
515
|
-
$input.isValid(validators);
|
|
555
|
+
ClientSideValidations.isValid(input, validators)
|
|
516
556
|
|
|
517
557
|
// Validate the whole form
|
|
518
|
-
|
|
558
|
+
ClientSideValidations.isValid(form, validators)
|
|
519
559
|
```
|
|
520
560
|
|
|
521
561
|
To manually validate a single field, you may also trigger a focusout event:
|
|
522
562
|
|
|
523
563
|
```js
|
|
524
|
-
|
|
564
|
+
input.dispatchEvent(new Event('focusout', { bubbles: true }))
|
|
525
565
|
```
|
|
526
566
|
|
|
527
567
|
## Authors ##
|
|
@@ -86,7 +86,7 @@ module ClientSideValidations
|
|
|
86
86
|
@validators.each_with_object({}) do |object_opts, validator_hash|
|
|
87
87
|
next unless object_opts[0].respond_to?(:client_side_validation_hash)
|
|
88
88
|
|
|
89
|
-
option_hash = object_opts[1].each_with_object({}) do |attr, result|
|
|
89
|
+
option_hash = object_opts[1].each_with_object({}) do |attr, result| # rubocop:disable Style/ReduceToHash -- False positive
|
|
90
90
|
result[attr[0]] = attr[1][:options]
|
|
91
91
|
end
|
|
92
92
|
|