client_side_validations 18.0.0 → 19.1.1
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 +28 -0
- data/README.md +33 -32
- data/lib/client_side_validations/action_view/form_builder.rb +6 -1
- data/lib/client_side_validations/active_model/conditionals.rb +0 -5
- data/lib/client_side_validations/active_model/numericality.rb +8 -1
- data/lib/client_side_validations/active_model.rb +8 -7
- data/lib/client_side_validations/version.rb +1 -1
- data/vendor/assets/javascripts/rails.validations.js +186 -177
- metadata +17 -92
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 976902dc549fbeaa2a7d127fe814715f51588643335720ff8b5dc36336c22e55
|
|
4
|
+
data.tar.gz: 2cb0ad62989f559f67a2671f4261365fb794383cb06b09abde9f27af1f57d9b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 56615d4a1fa647510bee9bf85861baa49117fb9e1775e29928b0d44971e6ee7180e6e3918c0f1cd9324b26a7d168eecbb4846f5eafcdf8cc549240537c09bb2d
|
|
7
|
+
data.tar.gz: bdd57bb1c3cd65be7d04bf07a50d1fde2b5646d30dc85d8bef30b19a8d1ad9b99742291e5dae0837b1637c12da3fabe960681137e25dc3cecebb2e1c41d77e86
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 19.1.1 / 2021-11-15
|
|
4
|
+
|
|
5
|
+
* [ENHANCEMENT] Require MFA to publish gems
|
|
6
|
+
* [ENHANCEMENT] Update development dependencies
|
|
7
|
+
|
|
8
|
+
## 19.1.0 / 2021-10-05
|
|
9
|
+
|
|
10
|
+
* [FEATURE] Add Turbo compatibility ([#849](https://github.com/DavyJonesLocker/client_side_validations/pull/849))
|
|
11
|
+
|
|
12
|
+
## 19.0.0 / 2021-10-01
|
|
13
|
+
|
|
14
|
+
* [FEATURE] Add support to `other_than` numericality validator
|
|
15
|
+
* [FEATURE] Drop Ruby 2.4 support
|
|
16
|
+
* [FEATURE] Drop Rails 5.0 and 5.1 support
|
|
17
|
+
* [FEATURE] Drop legacy browsers support (including IE8 and IE9)
|
|
18
|
+
* [FEATURE] Drop Yarn < 1.19 and Node < 12.0 support
|
|
19
|
+
* [FEATURE] Add JavaScript sources to node package
|
|
20
|
+
* [ENHANCEMENT] Minor JS Refactor
|
|
21
|
+
* [ENHANCEMENT] Update development dependencies
|
|
22
|
+
* [ENHANCEMENT] Update QUnit to 2.17.2
|
|
23
|
+
|
|
24
|
+
## 18.1.0 / 2021-06-13
|
|
25
|
+
|
|
26
|
+
* [FEATURE] Add support to `fields` method ([#828](https://github.com/DavyJonesLocker/client_side_validations/pull/828))
|
|
27
|
+
* [ENHANCEMENT] Test against jQuery 3.6.0 by default
|
|
28
|
+
* [ENHANCEMENT] Test against latest Ruby versions
|
|
29
|
+
* [ENHANCEMENT] Update QUnit to 2.15.0
|
|
30
|
+
|
|
3
31
|
## 18.0.0 / 2021-02-13
|
|
4
32
|
|
|
5
33
|
* [FEATURE] Add Rails 7.0.pre compatibility
|
data/README.md
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
[](https://badge.fury.io/rb/client_side_validations)
|
|
4
4
|
[](https://badge.fury.io/js/%40client-side-validations%2Fclient-side-validations)
|
|
5
5
|
[](https://dependabot.com/compatibility-score.html?dependency-name=client_side_validations&package-manager=bundler&version-scheme=semver)
|
|
6
|
-
[](https://github.com/DavyJonesLocker/client_side_validations/actions)
|
|
7
|
+
[](https://github.com/DavyJonesLocker/client_side_validations/actions)
|
|
7
8
|
[](https://codeclimate.com/github/DavyJonesLocker/client_side_validations/maintainability)
|
|
8
9
|
[](https://coveralls.io/github/DavyJonesLocker/client_side_validations?branch=main)
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
`ClientSideValidations` made easy for your Rails 5.
|
|
12
|
+
`ClientSideValidations` made easy for your Rails 5.2 / Rails 6.x applications!
|
|
12
13
|
|
|
13
14
|
## Project Goals ##
|
|
14
15
|
|
|
@@ -72,23 +73,23 @@ Then add the following line to your `app/javascript/packs/application.js` pack:
|
|
|
72
73
|
|
|
73
74
|
```js
|
|
74
75
|
// If you are using `import` syntax
|
|
75
|
-
import '@client-side-validations/client-side-validations'
|
|
76
|
+
import '@client-side-validations/client-side-validations/src'
|
|
76
77
|
|
|
77
78
|
// If you are using `require` syntax
|
|
78
79
|
require('@client-side-validations/client-side-validations')
|
|
79
80
|
```
|
|
80
81
|
|
|
81
|
-
##### Heads-up for Turbolinks users #####
|
|
82
|
+
##### Heads-up for Turbo and Turbolinks users #####
|
|
82
83
|
|
|
83
|
-
If you are using [
|
|
84
|
-
|
|
85
|
-
is
|
|
86
|
-
attach its event handlers.
|
|
84
|
+
If you are using [Turbo](https://github.com/hotwired/turbo-rails), use the
|
|
85
|
+
`import` syntax and make sure that `@client-side-validations/client-side-validations/src`
|
|
86
|
+
is imported **after** `@hotwired/turbo-rails`, so ClientSideValidations can properly detect
|
|
87
|
+
`window.Turbo` and attach its event handlers.
|
|
87
88
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
**after** `
|
|
91
|
-
attach its event handlers.
|
|
89
|
+
If you are using [Turbolinks](https://github.com/turbolinks/turbolinks) 5.2,
|
|
90
|
+
use the `require` syntax and make sure that `@client-side-validations/client-side-validations`
|
|
91
|
+
is required **after** `Turbolinks.start()`, so ClientSideValidations can properly
|
|
92
|
+
detect `window.Turbolinks` and attach its event handlers.
|
|
92
93
|
|
|
93
94
|
#### When using Sprockets ####
|
|
94
95
|
|
|
@@ -160,8 +161,8 @@ In your `FormBuilder` you only need to enable validations:
|
|
|
160
161
|
|
|
161
162
|
That should be enough to get you going.
|
|
162
163
|
|
|
163
|
-
Starting from version 14.0, ClientSideValidations also supports `form_with
|
|
164
|
-
|
|
164
|
+
Starting from version 14.0, ClientSideValidations also supports `form_with`.
|
|
165
|
+
The syntax is the same as `form_for`:
|
|
165
166
|
|
|
166
167
|
```erb
|
|
167
168
|
<%= form_with model: @user, validate: true do |f| %>
|
|
@@ -324,11 +325,11 @@ If you need to change the markup of how the errors are rendered you can modify t
|
|
|
324
325
|
|
|
325
326
|
```js
|
|
326
327
|
window.ClientSideValidations.formBuilders['ActionView::Helpers::FormBuilder'] = {
|
|
327
|
-
add: function(element, settings, message) {
|
|
328
|
+
add: function($element, settings, message) {
|
|
328
329
|
// custom add code here
|
|
329
330
|
},
|
|
330
331
|
|
|
331
|
-
remove: function(element, settings) {
|
|
332
|
+
remove: function($element, settings) {
|
|
332
333
|
// custom remove code here
|
|
333
334
|
}
|
|
334
335
|
}
|
|
@@ -378,9 +379,9 @@ Finally we need to add a client side validator. This can be done by hooking into
|
|
|
378
379
|
```js
|
|
379
380
|
// The validator variable is a JSON Object
|
|
380
381
|
// The selector variable is a jQuery Object
|
|
381
|
-
window.ClientSideValidations.validators.local['email'] = function(element, options) {
|
|
382
|
+
window.ClientSideValidations.validators.local['email'] = function($element, options) {
|
|
382
383
|
// Your validator code goes in here
|
|
383
|
-
if (!/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i.test(element.val())) {
|
|
384
|
+
if (!/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i.test($element.val())) {
|
|
384
385
|
// When the value fails to pass validation you need to return the error message.
|
|
385
386
|
// It can be derived from validator.message
|
|
386
387
|
return options.message;
|
|
@@ -439,14 +440,14 @@ $(form).resetClientSideValidations();
|
|
|
439
440
|
|
|
440
441
|
`ClientSideValidations` will run callbacks based upon the state of the element or form. The following callbacks are supported:
|
|
441
442
|
|
|
442
|
-
* `ClientSideValidations.callbacks.element.after(element, eventData)`
|
|
443
|
-
* `ClientSideValidations.callbacks.element.before(element, eventData)`
|
|
444
|
-
* `ClientSideValidations.callbacks.element.fail(element, message, callback, eventData)`
|
|
445
|
-
* `ClientSideValidations.callbacks.element.pass(element, callback, eventData)`
|
|
446
|
-
* `ClientSideValidations.callbacks.form.after(form, eventData)`
|
|
447
|
-
* `ClientSideValidations.callbacks.form.before(form, eventData)`
|
|
448
|
-
* `ClientSideValidations.callbacks.form.fail(form, eventData)`
|
|
449
|
-
* `ClientSideValidations.callbacks.form.pass(form, eventData)`
|
|
443
|
+
* `ClientSideValidations.callbacks.element.after($element, eventData)`
|
|
444
|
+
* `ClientSideValidations.callbacks.element.before($element, eventData)`
|
|
445
|
+
* `ClientSideValidations.callbacks.element.fail($element, message, callback, eventData)`
|
|
446
|
+
* `ClientSideValidations.callbacks.element.pass($element, callback, eventData)`
|
|
447
|
+
* `ClientSideValidations.callbacks.form.after($form, eventData)`
|
|
448
|
+
* `ClientSideValidations.callbacks.form.before($form, eventData)`
|
|
449
|
+
* `ClientSideValidations.callbacks.form.fail($form, eventData)`
|
|
450
|
+
* `ClientSideValidations.callbacks.form.pass($form, eventData)`
|
|
450
451
|
|
|
451
452
|
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
453
|
|
|
@@ -458,17 +459,17 @@ Here is an example callback for sliding out the error message when the validatio
|
|
|
458
459
|
|
|
459
460
|
``` javascript
|
|
460
461
|
// You will need to require 'jquery-ui' for this to work
|
|
461
|
-
window.ClientSideValidations.callbacks.element.fail = function(element, message, callback) {
|
|
462
|
+
window.ClientSideValidations.callbacks.element.fail = function($element, message, callback) {
|
|
462
463
|
callback();
|
|
463
|
-
if (element.data('valid') !== false) {
|
|
464
|
-
element.parent().find('.message').hide().show('slide', {direction: "left", easing: "easeOutBounce"}, 500);
|
|
464
|
+
if ($element.data('valid') !== false) {
|
|
465
|
+
$element.parent().find('.message').hide().show('slide', {direction: "left", easing: "easeOutBounce"}, 500);
|
|
465
466
|
}
|
|
466
467
|
}
|
|
467
468
|
|
|
468
|
-
window.ClientSideValidations.callbacks.element.pass = function(element, callback) {
|
|
469
|
+
window.ClientSideValidations.callbacks.element.pass = function($element, callback) {
|
|
469
470
|
// Take note how we're passing the callback to the hide()
|
|
470
471
|
// method so it is run after the animation is complete.
|
|
471
|
-
element.parent().find('.message').hide('slide', {direction: "left"}, 500, callback);
|
|
472
|
+
$element.parent().find('.message').hide('slide', {direction: "left"}, 500, callback);
|
|
472
473
|
}
|
|
473
474
|
```
|
|
474
475
|
|
|
@@ -506,7 +507,7 @@ If for some reason you would like to manually validate the form (for example you
|
|
|
506
507
|
|
|
507
508
|
```js
|
|
508
509
|
$input = $('#myInputField');
|
|
509
|
-
$form = $input.
|
|
510
|
+
$form = $($input[0].form);
|
|
510
511
|
validators = $form[0].ClientSideValidations.settings.validators;
|
|
511
512
|
|
|
512
513
|
// Validate a single field
|
|
@@ -5,7 +5,7 @@ module ClientSideValidations
|
|
|
5
5
|
module Helpers
|
|
6
6
|
module FormBuilder
|
|
7
7
|
def self.prepended(base)
|
|
8
|
-
(base.field_helpers - %i[label check_box radio_button fields_for hidden_field file_field]).each do |selector|
|
|
8
|
+
(base.field_helpers - %i[label check_box radio_button fields_for fields hidden_field file_field]).each do |selector|
|
|
9
9
|
base.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
|
10
10
|
# Cannot call super here, rewrite all
|
|
11
11
|
def #{selector}(method, options = {}) # def text_field(method, options = {})
|
|
@@ -72,6 +72,11 @@ module ClientSideValidations
|
|
|
72
72
|
super(record_name, record_object, fields_options, &block)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
def fields(scope = nil, model: nil, **options, &block)
|
|
76
|
+
options[:validate] ||= @options[:validate] if @options[:validate] && !options.key?(:validate)
|
|
77
|
+
super(scope, model: model, **options, &block)
|
|
78
|
+
end
|
|
79
|
+
|
|
75
80
|
def file_field(method, options = {})
|
|
76
81
|
build_validation_options(method, options)
|
|
77
82
|
options.delete(:validate)
|
|
@@ -27,11 +27,6 @@ module ClientSideValidations
|
|
|
27
27
|
else
|
|
28
28
|
raise ArgumentError, 'Missing argument'
|
|
29
29
|
end
|
|
30
|
-
when String
|
|
31
|
-
# rubocop:disable Security/Eval, Style/DocumentDynamicEvalDefinition
|
|
32
|
-
l = eval("->(value) { #{conditional} }", binding, __FILE__, __LINE__)
|
|
33
|
-
# rubocop:enable Security/Eval, Style/DocumentDynamicEvalDefinition
|
|
34
|
-
instance_exec(nil, &l)
|
|
35
30
|
when Symbol
|
|
36
31
|
send conditional
|
|
37
32
|
else
|
|
@@ -6,7 +6,14 @@ module ClientSideValidations
|
|
|
6
6
|
@@option_map = {}
|
|
7
7
|
|
|
8
8
|
def self.included(base)
|
|
9
|
-
|
|
9
|
+
checks =
|
|
10
|
+
if base.const_defined?('RESERVED_OPTIONS')
|
|
11
|
+
base::RESERVED_OPTIONS - [:only_integer]
|
|
12
|
+
else
|
|
13
|
+
base::CHECKS.keys
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
@@option_map.merge!(checks.inject({}) { |acc, elem| acc.merge!(elem => elem) })
|
|
10
17
|
super
|
|
11
18
|
end
|
|
12
19
|
|
|
@@ -18,19 +18,20 @@ module ClientSideValidations
|
|
|
18
18
|
private
|
|
19
19
|
|
|
20
20
|
def build_client_side_hash(model, attribute, options)
|
|
21
|
-
callbacks_options =
|
|
22
|
-
if Rails.version >= '6.1'
|
|
23
|
-
::ActiveModel::Error::CALLBACKS_OPTIONS
|
|
24
|
-
else
|
|
25
|
-
::ActiveModel::Errors::CALLBACKS_OPTIONS
|
|
26
|
-
end
|
|
27
|
-
|
|
28
21
|
{ message: model.errors.generate_message(attribute, message_type, options) }.merge(options.except(*callbacks_options - %i[allow_blank if unless]))
|
|
29
22
|
end
|
|
30
23
|
|
|
31
24
|
def message_type
|
|
32
25
|
kind
|
|
33
26
|
end
|
|
27
|
+
|
|
28
|
+
def callbacks_options
|
|
29
|
+
if defined?(::ActiveModel::Errors::CALLBACKS_OPTIONS)
|
|
30
|
+
::ActiveModel::Errors::CALLBACKS_OPTIONS
|
|
31
|
+
else
|
|
32
|
+
::ActiveModel::Error::CALLBACKS_OPTIONS
|
|
33
|
+
end
|
|
34
|
+
end
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
module Validations
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Client Side Validations JS - v0.
|
|
2
|
+
* Client Side Validations JS - v0.3.0 (https://github.com/DavyJonesLocker/client_side_validations)
|
|
3
3
|
* Copyright (c) 2021 Geremia Taglialatela, Brian Cardarella
|
|
4
4
|
* Licensed under MIT (https://opensource.org/licenses/mit-license.php)
|
|
5
5
|
*/
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
(function (global, factory) {
|
|
8
8
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) :
|
|
9
9
|
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
|
|
10
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ClientSideValidations = factory(global
|
|
11
|
-
}(this, (function (
|
|
10
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ClientSideValidations = factory(global.jQuery));
|
|
11
|
+
})(this, (function (jQuery) { 'use strict';
|
|
12
12
|
|
|
13
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var jQuery__default = /*#__PURE__*/_interopDefaultLegacy(jQuery);
|
|
16
16
|
|
|
17
17
|
function _typeof(obj) {
|
|
18
18
|
"@babel/helpers - typeof";
|
|
@@ -33,20 +33,20 @@
|
|
|
33
33
|
var ClientSideValidations = {
|
|
34
34
|
callbacks: {
|
|
35
35
|
element: {
|
|
36
|
-
after: function after(element, eventData) {},
|
|
37
|
-
before: function before(element, eventData) {},
|
|
38
|
-
fail: function fail(element, message, addError, eventData) {
|
|
36
|
+
after: function after($element, eventData) {},
|
|
37
|
+
before: function before($element, eventData) {},
|
|
38
|
+
fail: function fail($element, message, addError, eventData) {
|
|
39
39
|
return addError();
|
|
40
40
|
},
|
|
41
|
-
pass: function pass(element, removeError, eventData) {
|
|
41
|
+
pass: function pass($element, removeError, eventData) {
|
|
42
42
|
return removeError();
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
form: {
|
|
46
|
-
after: function after(form, eventData) {},
|
|
47
|
-
before: function before(form, eventData) {},
|
|
48
|
-
fail: function fail(form, eventData) {},
|
|
49
|
-
pass: function pass(form, eventData) {}
|
|
46
|
+
after: function after($form, eventData) {},
|
|
47
|
+
before: function before($form, eventData) {},
|
|
48
|
+
fail: function fail($form, eventData) {},
|
|
49
|
+
pass: function pass($form, eventData) {}
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
eventsToBind: {
|
|
@@ -80,52 +80,52 @@
|
|
|
80
80
|
input: function input(form) {
|
|
81
81
|
return {
|
|
82
82
|
'focusout.ClientSideValidations': function focusoutClientSideValidations() {
|
|
83
|
-
|
|
83
|
+
jQuery__default["default"](this).isValid(form.ClientSideValidations.settings.validators);
|
|
84
84
|
},
|
|
85
85
|
'change.ClientSideValidations': function changeClientSideValidations() {
|
|
86
|
-
|
|
86
|
+
jQuery__default["default"](this).data('changed', true);
|
|
87
87
|
},
|
|
88
88
|
'element:validate:after.ClientSideValidations': function elementValidateAfterClientSideValidations(eventData) {
|
|
89
|
-
ClientSideValidations.callbacks.element.after(
|
|
89
|
+
ClientSideValidations.callbacks.element.after(jQuery__default["default"](this), eventData);
|
|
90
90
|
},
|
|
91
91
|
'element:validate:before.ClientSideValidations': function elementValidateBeforeClientSideValidations(eventData) {
|
|
92
|
-
ClientSideValidations.callbacks.element.before(
|
|
92
|
+
ClientSideValidations.callbacks.element.before(jQuery__default["default"](this), eventData);
|
|
93
93
|
},
|
|
94
94
|
'element:validate:fail.ClientSideValidations': function elementValidateFailClientSideValidations(eventData, message) {
|
|
95
|
-
var $element =
|
|
95
|
+
var $element = jQuery__default["default"](this);
|
|
96
96
|
ClientSideValidations.callbacks.element.fail($element, message, function () {
|
|
97
|
-
|
|
97
|
+
form.ClientSideValidations.addError($element, message);
|
|
98
98
|
}, eventData);
|
|
99
99
|
},
|
|
100
100
|
'element:validate:pass.ClientSideValidations': function elementValidatePassClientSideValidations(eventData) {
|
|
101
|
-
var $element =
|
|
101
|
+
var $element = jQuery__default["default"](this);
|
|
102
102
|
ClientSideValidations.callbacks.element.pass($element, function () {
|
|
103
|
-
|
|
103
|
+
form.ClientSideValidations.removeError($element);
|
|
104
104
|
}, eventData);
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
107
|
},
|
|
108
|
-
inputConfirmation: function inputConfirmation(element, form) {
|
|
108
|
+
inputConfirmation: function inputConfirmation($element, form) {
|
|
109
109
|
return {
|
|
110
110
|
'focusout.ClientSideValidations': function focusoutClientSideValidations() {
|
|
111
|
-
element.data('changed', true).isValid(form.ClientSideValidations.settings.validators);
|
|
111
|
+
$element.data('changed', true).isValid(form.ClientSideValidations.settings.validators);
|
|
112
112
|
},
|
|
113
113
|
'keyup.ClientSideValidations': function keyupClientSideValidations() {
|
|
114
|
-
element.data('changed', true).isValid(form.ClientSideValidations.settings.validators);
|
|
114
|
+
$element.data('changed', true).isValid(form.ClientSideValidations.settings.validators);
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
118
|
},
|
|
119
119
|
enablers: {
|
|
120
120
|
form: function form(_form2) {
|
|
121
|
-
var $form =
|
|
121
|
+
var $form = jQuery__default["default"](_form2);
|
|
122
122
|
_form2.ClientSideValidations = {
|
|
123
123
|
settings: $form.data('clientSideValidations'),
|
|
124
|
-
addError: function addError(element, message) {
|
|
125
|
-
return ClientSideValidations.formBuilders[_form2.ClientSideValidations.settings.html_settings.type].add(element, _form2.ClientSideValidations.settings.html_settings, message);
|
|
124
|
+
addError: function addError($element, message) {
|
|
125
|
+
return ClientSideValidations.formBuilders[_form2.ClientSideValidations.settings.html_settings.type].add($element, _form2.ClientSideValidations.settings.html_settings, message);
|
|
126
126
|
},
|
|
127
|
-
removeError: function removeError(element) {
|
|
128
|
-
return ClientSideValidations.formBuilders[_form2.ClientSideValidations.settings.html_settings.type].remove(element, _form2.ClientSideValidations.settings.html_settings);
|
|
127
|
+
removeError: function removeError($element) {
|
|
128
|
+
return ClientSideValidations.formBuilders[_form2.ClientSideValidations.settings.html_settings.type].remove($element, _form2.ClientSideValidations.settings.html_settings);
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
var eventsToBind = ClientSideValidations.eventsToBind.form(_form2, $form);
|
|
@@ -140,31 +140,31 @@
|
|
|
140
140
|
});
|
|
141
141
|
},
|
|
142
142
|
input: function input(_input) {
|
|
143
|
-
var $input =
|
|
143
|
+
var $input = jQuery__default["default"](_input);
|
|
144
144
|
var form = _input.form;
|
|
145
|
-
var $form =
|
|
145
|
+
var $form = jQuery__default["default"](form);
|
|
146
146
|
var eventsToBind = ClientSideValidations.eventsToBind.input(form);
|
|
147
147
|
|
|
148
148
|
for (var eventName in eventsToBind) {
|
|
149
149
|
var eventFunction = eventsToBind[eventName];
|
|
150
150
|
$input.filter(':not(:radio):not([id$=_confirmation])').each(function () {
|
|
151
|
-
|
|
151
|
+
jQuery__default["default"](this).attr('data-validate', true);
|
|
152
152
|
}).on(eventName, eventFunction);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
$input.filter(':checkbox').on('change.ClientSideValidations', function () {
|
|
156
|
-
|
|
156
|
+
jQuery__default["default"](this).isValid(form.ClientSideValidations.settings.validators);
|
|
157
157
|
});
|
|
158
158
|
$input.filter('[id$=_confirmation]').each(function () {
|
|
159
|
-
var $element =
|
|
160
|
-
var $elementToConfirm = $form.find(
|
|
159
|
+
var $element = jQuery__default["default"](this);
|
|
160
|
+
var $elementToConfirm = $form.find("#".concat(this.id.match(/(.+)_confirmation/)[1], ":input"));
|
|
161
161
|
|
|
162
162
|
if ($elementToConfirm.length) {
|
|
163
163
|
var _eventsToBind = ClientSideValidations.eventsToBind.inputConfirmation($elementToConfirm, form);
|
|
164
164
|
|
|
165
165
|
for (var _eventName in _eventsToBind) {
|
|
166
166
|
var _eventFunction = _eventsToBind[_eventName];
|
|
167
|
-
|
|
167
|
+
jQuery__default["default"]("#".concat($element.attr('id'))).on(_eventName, _eventFunction);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
});
|
|
@@ -172,48 +172,48 @@
|
|
|
172
172
|
},
|
|
173
173
|
formBuilders: {
|
|
174
174
|
'ActionView::Helpers::FormBuilder': {
|
|
175
|
-
add: function add(element, settings, message) {
|
|
176
|
-
var form =
|
|
175
|
+
add: function add($element, settings, message) {
|
|
176
|
+
var $form = jQuery__default["default"]($element[0].form);
|
|
177
177
|
|
|
178
|
-
if (element.data('valid') !== false && form.find("label.message[for
|
|
179
|
-
var inputErrorField =
|
|
180
|
-
var labelErrorField =
|
|
181
|
-
var label = form.find("label[for
|
|
178
|
+
if ($element.data('valid') !== false && $form.find("label.message[for=\"".concat($element.attr('id'), "\"]"))[0] == null) {
|
|
179
|
+
var $inputErrorField = jQuery__default["default"](settings.input_tag);
|
|
180
|
+
var $labelErrorField = jQuery__default["default"](settings.label_tag);
|
|
181
|
+
var $label = $form.find("label[for=\"".concat($element.attr('id'), "\"]:not(.message)"));
|
|
182
182
|
|
|
183
|
-
if (element.attr('autofocus')) {
|
|
184
|
-
element.attr('autofocus', false);
|
|
183
|
+
if ($element.attr('autofocus')) {
|
|
184
|
+
$element.attr('autofocus', false);
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
element.before(inputErrorField);
|
|
188
|
-
inputErrorField.find('span#input_tag').replaceWith(element);
|
|
189
|
-
inputErrorField.find('label.message').attr('for', element.attr('id'));
|
|
190
|
-
labelErrorField.find('label.message').attr('for', element.attr('id'));
|
|
191
|
-
labelErrorField.insertAfter(label);
|
|
192
|
-
labelErrorField.find('label#label_tag').replaceWith(label);
|
|
187
|
+
$element.before($inputErrorField);
|
|
188
|
+
$inputErrorField.find('span#input_tag').replaceWith($element);
|
|
189
|
+
$inputErrorField.find('label.message').attr('for', $element.attr('id'));
|
|
190
|
+
$labelErrorField.find('label.message').attr('for', $element.attr('id'));
|
|
191
|
+
$labelErrorField.insertAfter($label);
|
|
192
|
+
$labelErrorField.find('label#label_tag').replaceWith($label);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
form.find("label.message[for
|
|
195
|
+
$form.find("label.message[for=\"".concat($element.attr('id'), "\"]")).text(message);
|
|
196
196
|
},
|
|
197
|
-
remove: function remove(element, settings) {
|
|
198
|
-
var form =
|
|
199
|
-
var inputErrorFieldClass =
|
|
200
|
-
var inputErrorField = element.closest(
|
|
201
|
-
var label = form.find("label[for
|
|
202
|
-
var labelErrorFieldClass =
|
|
203
|
-
var labelErrorField = label.closest(
|
|
204
|
-
|
|
205
|
-
if (inputErrorField[0]) {
|
|
206
|
-
inputErrorField.find(
|
|
207
|
-
inputErrorField.replaceWith(element);
|
|
208
|
-
label.detach();
|
|
209
|
-
labelErrorField.replaceWith(label);
|
|
197
|
+
remove: function remove($element, settings) {
|
|
198
|
+
var $form = jQuery__default["default"]($element[0].form);
|
|
199
|
+
var $inputErrorFieldClass = jQuery__default["default"](settings.input_tag).attr('class');
|
|
200
|
+
var $inputErrorField = $element.closest(".".concat($inputErrorFieldClass.replace(/ /g, '.')));
|
|
201
|
+
var $label = $form.find("label[for=\"".concat($element.attr('id'), "\"]:not(.message)"));
|
|
202
|
+
var $labelErrorFieldClass = jQuery__default["default"](settings.label_tag).attr('class');
|
|
203
|
+
var $labelErrorField = $label.closest(".".concat($labelErrorFieldClass.replace(/ /g, '.')));
|
|
204
|
+
|
|
205
|
+
if ($inputErrorField[0]) {
|
|
206
|
+
$inputErrorField.find("#".concat($element.attr('id'))).detach();
|
|
207
|
+
$inputErrorField.replaceWith($element);
|
|
208
|
+
$label.detach();
|
|
209
|
+
$labelErrorField.replaceWith($label);
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
},
|
|
214
214
|
patterns: {
|
|
215
215
|
numericality: {
|
|
216
|
-
|
|
216
|
+
default: /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/,
|
|
217
217
|
only_integer: /^[+-]?\d+$/
|
|
218
218
|
}
|
|
219
219
|
},
|
|
@@ -224,13 +224,13 @@
|
|
|
224
224
|
},
|
|
225
225
|
validators: {
|
|
226
226
|
all: function all() {
|
|
227
|
-
return
|
|
227
|
+
return jQuery__default["default"].extend({}, ClientSideValidations.validators.local, ClientSideValidations.validators.remote);
|
|
228
228
|
},
|
|
229
229
|
local: {},
|
|
230
230
|
remote: {}
|
|
231
231
|
},
|
|
232
232
|
disable: function disable(target) {
|
|
233
|
-
var $target =
|
|
233
|
+
var $target = jQuery__default["default"](target);
|
|
234
234
|
$target.off('.ClientSideValidations');
|
|
235
235
|
|
|
236
236
|
if ($target.is('form')) {
|
|
@@ -238,29 +238,37 @@
|
|
|
238
238
|
} else {
|
|
239
239
|
$target.removeData(['changed', 'valid']);
|
|
240
240
|
$target.filter(':input').each(function () {
|
|
241
|
-
|
|
241
|
+
jQuery__default["default"](this).removeAttr('data-validate');
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
244
|
},
|
|
245
245
|
reset: function reset(form) {
|
|
246
|
-
var $form =
|
|
246
|
+
var $form = jQuery__default["default"](form);
|
|
247
247
|
ClientSideValidations.disable(form);
|
|
248
248
|
|
|
249
249
|
for (var key in form.ClientSideValidations.settings.validators) {
|
|
250
|
-
form.ClientSideValidations.removeError($form.find("[name
|
|
250
|
+
form.ClientSideValidations.removeError($form.find("[name=\"".concat(key, "\"]")));
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
ClientSideValidations.enablers.form(form);
|
|
254
254
|
},
|
|
255
|
+
initializeOnEvent: function initializeOnEvent() {
|
|
256
|
+
if (window.Turbo != null) {
|
|
257
|
+
return 'turbo:load';
|
|
258
|
+
} else if (window.Turbolinks != null && window.Turbolinks.supported) {
|
|
259
|
+
return window.Turbolinks.EVENTS != null ? 'page:change' : 'turbolinks:load';
|
|
260
|
+
}
|
|
261
|
+
},
|
|
255
262
|
start: function start() {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
263
|
+
var initializeOnEvent = ClientSideValidations.initializeOnEvent();
|
|
264
|
+
|
|
265
|
+
if (initializeOnEvent != null) {
|
|
266
|
+
jQuery__default["default"](document).on(initializeOnEvent, function () {
|
|
267
|
+
return jQuery__default["default"](ClientSideValidations.selectors.forms).validate();
|
|
260
268
|
});
|
|
261
269
|
} else {
|
|
262
|
-
|
|
263
|
-
return
|
|
270
|
+
jQuery__default["default"](function () {
|
|
271
|
+
return jQuery__default["default"](ClientSideValidations.selectors.forms).validate();
|
|
264
272
|
});
|
|
265
273
|
}
|
|
266
274
|
}
|
|
@@ -275,26 +283,22 @@
|
|
|
275
283
|
|
|
276
284
|
return false;
|
|
277
285
|
};
|
|
278
|
-
var
|
|
286
|
+
var isValuePresent = function isValuePresent(value) {
|
|
279
287
|
return !/^\s*$/.test(value || '');
|
|
280
288
|
};
|
|
281
289
|
|
|
282
|
-
var absenceLocalValidator = function absenceLocalValidator(element, options) {
|
|
283
|
-
if (
|
|
290
|
+
var absenceLocalValidator = function absenceLocalValidator($element, options) {
|
|
291
|
+
if (isValuePresent($element.val())) {
|
|
284
292
|
return options.message;
|
|
285
293
|
}
|
|
286
294
|
};
|
|
287
|
-
var presenceLocalValidator = function presenceLocalValidator(element, options) {
|
|
288
|
-
if (!
|
|
295
|
+
var presenceLocalValidator = function presenceLocalValidator($element, options) {
|
|
296
|
+
if (!isValuePresent($element.val())) {
|
|
289
297
|
return options.message;
|
|
290
298
|
}
|
|
291
299
|
};
|
|
292
300
|
|
|
293
301
|
var DEFAULT_ACCEPT_OPTION = ['1', true];
|
|
294
|
-
Array.isArray || (Array.isArray = function (a) {
|
|
295
|
-
var object = {};
|
|
296
|
-
return '' + a !== a && object.toString.call(a) === '[object Array]';
|
|
297
|
-
});
|
|
298
302
|
|
|
299
303
|
var isTextAccepted = function isTextAccepted(value, acceptOption) {
|
|
300
304
|
if (!acceptOption) {
|
|
@@ -308,15 +312,15 @@
|
|
|
308
312
|
return value === acceptOption;
|
|
309
313
|
};
|
|
310
314
|
|
|
311
|
-
var acceptanceLocalValidator = function acceptanceLocalValidator(element, options) {
|
|
315
|
+
var acceptanceLocalValidator = function acceptanceLocalValidator($element, options) {
|
|
312
316
|
var valid = true;
|
|
313
317
|
|
|
314
|
-
if (element.attr('type') === 'checkbox') {
|
|
315
|
-
valid = element.prop('checked');
|
|
318
|
+
if ($element.attr('type') === 'checkbox') {
|
|
319
|
+
valid = $element.prop('checked');
|
|
316
320
|
}
|
|
317
321
|
|
|
318
|
-
if (element.attr('type') === 'text') {
|
|
319
|
-
valid = isTextAccepted(element.val(), options.accept);
|
|
322
|
+
if ($element.attr('type') === 'text') {
|
|
323
|
+
valid = isTextAccepted($element.val(), options.accept);
|
|
320
324
|
}
|
|
321
325
|
|
|
322
326
|
if (!valid) {
|
|
@@ -332,19 +336,19 @@
|
|
|
332
336
|
return withOptions && isMatching(value, withOptions) || withoutOptions && !isMatching(value, withoutOptions);
|
|
333
337
|
};
|
|
334
338
|
|
|
335
|
-
var formatLocalValidator = function formatLocalValidator(element, options) {
|
|
336
|
-
var value = element.val();
|
|
339
|
+
var formatLocalValidator = function formatLocalValidator($element, options) {
|
|
340
|
+
var value = $element.val();
|
|
337
341
|
|
|
338
|
-
if (options.allow_blank && !
|
|
342
|
+
if (options.allow_blank && !isValuePresent(value)) {
|
|
339
343
|
return;
|
|
340
344
|
}
|
|
341
345
|
|
|
342
|
-
if (!hasValidFormat(value, options
|
|
346
|
+
if (!hasValidFormat(value, options.with, options.without)) {
|
|
343
347
|
return options.message;
|
|
344
348
|
}
|
|
345
349
|
};
|
|
346
350
|
|
|
347
|
-
var VALIDATIONS = {
|
|
351
|
+
var VALIDATIONS$1 = {
|
|
348
352
|
even: function even(a) {
|
|
349
353
|
return parseInt(a, 10) % 2 === 0;
|
|
350
354
|
},
|
|
@@ -365,6 +369,9 @@
|
|
|
365
369
|
},
|
|
366
370
|
odd: function odd(a) {
|
|
367
371
|
return parseInt(a, 10) % 2 === 1;
|
|
372
|
+
},
|
|
373
|
+
other_than: function other_than(a, b) {
|
|
374
|
+
return parseFloat(a) !== parseFloat(b);
|
|
368
375
|
}
|
|
369
376
|
};
|
|
370
377
|
|
|
@@ -373,11 +380,11 @@
|
|
|
373
380
|
return validationOption;
|
|
374
381
|
}
|
|
375
382
|
|
|
376
|
-
var validationElement = $form.find(
|
|
383
|
+
var validationElement = $form.find("[name*=\"".concat(validationOption, "\"]"));
|
|
377
384
|
|
|
378
385
|
if (validationElement.length === 1) {
|
|
379
386
|
var numberFormat = $form[0].ClientSideValidations.settings.number_format;
|
|
380
|
-
var otherFormattedValue =
|
|
387
|
+
var otherFormattedValue = jQuery__default["default"].trim(validationElement.val()).replace(new RegExp("\\".concat(numberFormat.separator), 'g'), '.');
|
|
381
388
|
|
|
382
389
|
if (!isNaN(parseFloat(otherFormattedValue))) {
|
|
383
390
|
return otherFormattedValue;
|
|
@@ -395,9 +402,9 @@
|
|
|
395
402
|
};
|
|
396
403
|
|
|
397
404
|
var runFunctionValidations = function runFunctionValidations(formattedValue, $form, options) {
|
|
398
|
-
for (var validation in VALIDATIONS) {
|
|
405
|
+
for (var validation in VALIDATIONS$1) {
|
|
399
406
|
var validationOption = options[validation];
|
|
400
|
-
var validationFunction = VALIDATIONS[validation]; // Must check for null because this could be 0
|
|
407
|
+
var validationFunction = VALIDATIONS$1[validation]; // Must check for null because this could be 0
|
|
401
408
|
|
|
402
409
|
if (validationOption == null) {
|
|
403
410
|
continue;
|
|
@@ -409,32 +416,32 @@
|
|
|
409
416
|
}
|
|
410
417
|
};
|
|
411
418
|
|
|
412
|
-
var runValidations = function runValidations(formattedValue, $form, options) {
|
|
419
|
+
var runValidations$1 = function runValidations(formattedValue, $form, options) {
|
|
413
420
|
if (options.only_integer && !ClientSideValidations.patterns.numericality.only_integer.test(formattedValue)) {
|
|
414
421
|
return options.messages.only_integer;
|
|
415
422
|
}
|
|
416
423
|
|
|
417
|
-
if (!ClientSideValidations.patterns.numericality
|
|
424
|
+
if (!ClientSideValidations.patterns.numericality.default.test(formattedValue)) {
|
|
418
425
|
return options.messages.numericality;
|
|
419
426
|
}
|
|
420
427
|
|
|
421
428
|
return runFunctionValidations(formattedValue, $form, options);
|
|
422
429
|
};
|
|
423
430
|
|
|
424
|
-
var numericalityLocalValidator = function numericalityLocalValidator(element, options) {
|
|
425
|
-
var value = element.val();
|
|
431
|
+
var numericalityLocalValidator = function numericalityLocalValidator($element, options) {
|
|
432
|
+
var value = $element.val();
|
|
426
433
|
|
|
427
|
-
if (options.allow_blank && !
|
|
434
|
+
if (options.allow_blank && !isValuePresent(value)) {
|
|
428
435
|
return;
|
|
429
436
|
}
|
|
430
437
|
|
|
431
|
-
var $form =
|
|
438
|
+
var $form = jQuery__default["default"]($element[0].form);
|
|
432
439
|
var numberFormat = $form[0].ClientSideValidations.settings.number_format;
|
|
433
|
-
var formattedValue =
|
|
434
|
-
return runValidations(formattedValue, $form, options);
|
|
440
|
+
var formattedValue = jQuery__default["default"].trim(value).replace(new RegExp("\\".concat(numberFormat.separator), 'g'), '.');
|
|
441
|
+
return runValidations$1(formattedValue, $form, options);
|
|
435
442
|
};
|
|
436
443
|
|
|
437
|
-
var VALIDATIONS
|
|
444
|
+
var VALIDATIONS = {
|
|
438
445
|
is: function is(a, b) {
|
|
439
446
|
return a === parseInt(b, 10);
|
|
440
447
|
},
|
|
@@ -446,10 +453,10 @@
|
|
|
446
453
|
}
|
|
447
454
|
};
|
|
448
455
|
|
|
449
|
-
var runValidations
|
|
450
|
-
for (var validation in VALIDATIONS
|
|
456
|
+
var runValidations = function runValidations(valueLength, options) {
|
|
457
|
+
for (var validation in VALIDATIONS) {
|
|
451
458
|
var validationOption = options[validation];
|
|
452
|
-
var validationFunction = VALIDATIONS
|
|
459
|
+
var validationFunction = VALIDATIONS[validation];
|
|
453
460
|
|
|
454
461
|
if (validationOption && !validationFunction(valueLength, validationOption)) {
|
|
455
462
|
return options.messages[validation];
|
|
@@ -457,14 +464,14 @@
|
|
|
457
464
|
}
|
|
458
465
|
};
|
|
459
466
|
|
|
460
|
-
var lengthLocalValidator = function lengthLocalValidator(element, options) {
|
|
461
|
-
var value = element.val();
|
|
467
|
+
var lengthLocalValidator = function lengthLocalValidator($element, options) {
|
|
468
|
+
var value = $element.val();
|
|
462
469
|
|
|
463
|
-
if (options.allow_blank && !
|
|
470
|
+
if (options.allow_blank && !isValuePresent(value)) {
|
|
464
471
|
return;
|
|
465
472
|
}
|
|
466
473
|
|
|
467
|
-
return runValidations
|
|
474
|
+
return runValidations(value.length, options);
|
|
468
475
|
};
|
|
469
476
|
|
|
470
477
|
var isInList = function isInList(value, otherValues) {
|
|
@@ -482,29 +489,31 @@
|
|
|
482
489
|
};
|
|
483
490
|
|
|
484
491
|
var isIncluded = function isIncluded(value, options, allowBlank) {
|
|
485
|
-
if ((options.allow_blank && !
|
|
492
|
+
if ((options.allow_blank && !isValuePresent(value)) === allowBlank) {
|
|
486
493
|
return true;
|
|
487
494
|
}
|
|
488
495
|
|
|
489
|
-
return options
|
|
496
|
+
return options.in && isInList(value, options.in) || options.range && isInRange(value, options.range);
|
|
490
497
|
};
|
|
491
498
|
|
|
492
|
-
var exclusionLocalValidator = function exclusionLocalValidator(element, options) {
|
|
493
|
-
var value = element.val();
|
|
499
|
+
var exclusionLocalValidator = function exclusionLocalValidator($element, options) {
|
|
500
|
+
var value = $element.val();
|
|
494
501
|
|
|
495
|
-
if (isIncluded(value, options, false) || !options.allow_blank && !
|
|
502
|
+
if (isIncluded(value, options, false) || !options.allow_blank && !isValuePresent(value)) {
|
|
496
503
|
return options.message;
|
|
497
504
|
}
|
|
498
505
|
};
|
|
499
|
-
var inclusionLocalValidator = function inclusionLocalValidator(element, options) {
|
|
500
|
-
|
|
506
|
+
var inclusionLocalValidator = function inclusionLocalValidator($element, options) {
|
|
507
|
+
var value = $element.val();
|
|
508
|
+
|
|
509
|
+
if (!isIncluded(value, options, true)) {
|
|
501
510
|
return options.message;
|
|
502
511
|
}
|
|
503
512
|
};
|
|
504
513
|
|
|
505
|
-
var confirmationLocalValidator = function confirmationLocalValidator(element, options) {
|
|
506
|
-
var value = element.val();
|
|
507
|
-
var confirmationValue =
|
|
514
|
+
var confirmationLocalValidator = function confirmationLocalValidator($element, options) {
|
|
515
|
+
var value = $element.val();
|
|
516
|
+
var confirmationValue = jQuery__default["default"]("#".concat($element.attr('id'), "_confirmation")).val();
|
|
508
517
|
|
|
509
518
|
if (!options.case_sensitive) {
|
|
510
519
|
value = value.toLowerCase();
|
|
@@ -523,30 +532,30 @@
|
|
|
523
532
|
}
|
|
524
533
|
|
|
525
534
|
if (otherValue === value) {
|
|
526
|
-
|
|
535
|
+
jQuery__default["default"](currentElement).data('notLocallyUnique', true);
|
|
527
536
|
return false;
|
|
528
537
|
}
|
|
529
538
|
|
|
530
|
-
if (
|
|
531
|
-
|
|
539
|
+
if (jQuery__default["default"](currentElement).data('notLocallyUnique')) {
|
|
540
|
+
jQuery__default["default"](currentElement).removeData('notLocallyUnique').data('changed', true);
|
|
532
541
|
}
|
|
533
542
|
|
|
534
543
|
return true;
|
|
535
544
|
};
|
|
536
545
|
|
|
537
|
-
var uniquenessLocalValidator = function uniquenessLocalValidator(element, options) {
|
|
538
|
-
var elementName = element.attr('name');
|
|
546
|
+
var uniquenessLocalValidator = function uniquenessLocalValidator($element, options) {
|
|
547
|
+
var elementName = $element.attr('name');
|
|
539
548
|
var matches = elementName.match(/^(.+_attributes\])\[\d+\](.+)$/);
|
|
540
549
|
|
|
541
550
|
if (!matches) {
|
|
542
551
|
return;
|
|
543
552
|
}
|
|
544
553
|
|
|
545
|
-
var form = element.
|
|
546
|
-
var value = element.val();
|
|
554
|
+
var $form = jQuery__default["default"]($element[0].form);
|
|
555
|
+
var value = $element.val();
|
|
547
556
|
var valid = true;
|
|
548
|
-
form.find(
|
|
549
|
-
var otherValue =
|
|
557
|
+
$form.find(":input[name^=\"".concat(matches[1], "\"][name$=\"").concat(matches[2], "\"]")).not($element).each(function () {
|
|
558
|
+
var otherValue = jQuery__default["default"](this).val();
|
|
550
559
|
|
|
551
560
|
if (!isLocallyUnique(this, value, otherValue, options.case_sensitive)) {
|
|
552
561
|
valid = false;
|
|
@@ -571,12 +580,12 @@
|
|
|
571
580
|
uniqueness: uniquenessLocalValidator
|
|
572
581
|
};
|
|
573
582
|
|
|
574
|
-
|
|
583
|
+
jQuery__default["default"].fn.disableClientSideValidations = function () {
|
|
575
584
|
ClientSideValidations.disable(this);
|
|
576
585
|
return this;
|
|
577
586
|
};
|
|
578
587
|
|
|
579
|
-
|
|
588
|
+
jQuery__default["default"].fn.enableClientSideValidations = function () {
|
|
580
589
|
var _this = this;
|
|
581
590
|
|
|
582
591
|
var selectors = {
|
|
@@ -588,7 +597,7 @@
|
|
|
588
597
|
var enablers = selectors[selector];
|
|
589
598
|
|
|
590
599
|
_this.filter(ClientSideValidations.selectors[selector]).each(function () {
|
|
591
|
-
|
|
600
|
+
ClientSideValidations.enablers[enablers](this);
|
|
592
601
|
});
|
|
593
602
|
};
|
|
594
603
|
|
|
@@ -599,22 +608,22 @@
|
|
|
599
608
|
return this;
|
|
600
609
|
};
|
|
601
610
|
|
|
602
|
-
|
|
611
|
+
jQuery__default["default"].fn.resetClientSideValidations = function () {
|
|
603
612
|
this.filter(ClientSideValidations.selectors.forms).each(function () {
|
|
604
|
-
|
|
613
|
+
ClientSideValidations.reset(this);
|
|
605
614
|
});
|
|
606
615
|
return this;
|
|
607
616
|
};
|
|
608
617
|
|
|
609
|
-
|
|
618
|
+
jQuery__default["default"].fn.validate = function () {
|
|
610
619
|
this.filter(ClientSideValidations.selectors.forms).each(function () {
|
|
611
|
-
|
|
620
|
+
jQuery__default["default"](this).enableClientSideValidations();
|
|
612
621
|
});
|
|
613
622
|
return this;
|
|
614
623
|
};
|
|
615
624
|
|
|
616
|
-
|
|
617
|
-
var obj =
|
|
625
|
+
jQuery__default["default"].fn.isValid = function (validators) {
|
|
626
|
+
var obj = jQuery__default["default"](this[0]);
|
|
618
627
|
|
|
619
628
|
if (obj.is('form')) {
|
|
620
629
|
return validateForm(obj, validators);
|
|
@@ -625,7 +634,7 @@
|
|
|
625
634
|
|
|
626
635
|
var cleanNestedElementName = function cleanNestedElementName(elementName, nestedMatches, validators) {
|
|
627
636
|
for (var validatorName in validators) {
|
|
628
|
-
if (validatorName.match(
|
|
637
|
+
if (validatorName.match("\\[".concat(nestedMatches[1], "\\].*\\[\\]\\[").concat(nestedMatches[2], "\\]$"))) {
|
|
629
638
|
elementName = elementName.replace(/\[[\da-z_]+\]\[(\w+)\]$/g, '[][$1]');
|
|
630
639
|
}
|
|
631
640
|
}
|
|
@@ -652,11 +661,11 @@
|
|
|
652
661
|
return validators[cleanElementName(elementName, validators)] || {};
|
|
653
662
|
};
|
|
654
663
|
|
|
655
|
-
var validateForm = function validateForm(form, validators) {
|
|
664
|
+
var validateForm = function validateForm($form, validators) {
|
|
656
665
|
var valid = true;
|
|
657
|
-
form.trigger('form:validate:before.ClientSideValidations');
|
|
658
|
-
form.find(ClientSideValidations.selectors.validate_inputs).each(function () {
|
|
659
|
-
if (
|
|
666
|
+
$form.trigger('form:validate:before.ClientSideValidations');
|
|
667
|
+
$form.find(ClientSideValidations.selectors.validate_inputs).each(function () {
|
|
668
|
+
if (!jQuery__default["default"](this).isValid(validators)) {
|
|
660
669
|
valid = false;
|
|
661
670
|
}
|
|
662
671
|
|
|
@@ -664,37 +673,37 @@
|
|
|
664
673
|
});
|
|
665
674
|
|
|
666
675
|
if (valid) {
|
|
667
|
-
form.trigger('form:validate:pass.ClientSideValidations');
|
|
676
|
+
$form.trigger('form:validate:pass.ClientSideValidations');
|
|
668
677
|
} else {
|
|
669
|
-
form.trigger('form:validate:fail.ClientSideValidations');
|
|
678
|
+
$form.trigger('form:validate:fail.ClientSideValidations');
|
|
670
679
|
}
|
|
671
680
|
|
|
672
|
-
form.trigger('form:validate:after.ClientSideValidations');
|
|
681
|
+
$form.trigger('form:validate:after.ClientSideValidations');
|
|
673
682
|
return valid;
|
|
674
683
|
};
|
|
675
684
|
|
|
676
|
-
var passElement = function passElement(element) {
|
|
677
|
-
element.trigger('element:validate:pass.ClientSideValidations').data('valid', null);
|
|
685
|
+
var passElement = function passElement($element) {
|
|
686
|
+
$element.trigger('element:validate:pass.ClientSideValidations').data('valid', null);
|
|
678
687
|
};
|
|
679
688
|
|
|
680
|
-
var failElement = function failElement(element, message) {
|
|
681
|
-
element.trigger('element:validate:fail.ClientSideValidations', message).data('valid', false);
|
|
689
|
+
var failElement = function failElement($element, message) {
|
|
690
|
+
$element.trigger('element:validate:fail.ClientSideValidations', message).data('valid', false);
|
|
682
691
|
};
|
|
683
692
|
|
|
684
|
-
var afterValidate = function afterValidate(element) {
|
|
685
|
-
return element.trigger('element:validate:after.ClientSideValidations').data('valid') !== false;
|
|
693
|
+
var afterValidate = function afterValidate($element) {
|
|
694
|
+
return $element.trigger('element:validate:after.ClientSideValidations').data('valid') !== false;
|
|
686
695
|
};
|
|
687
696
|
|
|
688
|
-
var executeValidator = function executeValidator(validatorFunctions, validatorFunction, validatorOptions, element) {
|
|
697
|
+
var executeValidator = function executeValidator(validatorFunctions, validatorFunction, validatorOptions, $element) {
|
|
689
698
|
for (var validatorOption in validatorOptions) {
|
|
690
699
|
if (!validatorOptions[validatorOption]) {
|
|
691
700
|
continue;
|
|
692
701
|
}
|
|
693
702
|
|
|
694
|
-
var message = validatorFunction.call(validatorFunctions, element, validatorOptions[validatorOption]);
|
|
703
|
+
var message = validatorFunction.call(validatorFunctions, $element, validatorOptions[validatorOption]);
|
|
695
704
|
|
|
696
705
|
if (message) {
|
|
697
|
-
failElement(element, message);
|
|
706
|
+
failElement($element, message);
|
|
698
707
|
return false;
|
|
699
708
|
}
|
|
700
709
|
}
|
|
@@ -702,13 +711,13 @@
|
|
|
702
711
|
return true;
|
|
703
712
|
};
|
|
704
713
|
|
|
705
|
-
var executeValidators = function executeValidators(validatorFunctions, element, validators) {
|
|
714
|
+
var executeValidators = function executeValidators(validatorFunctions, $element, validators) {
|
|
706
715
|
for (var validator in validators) {
|
|
707
716
|
if (!validatorFunctions[validator]) {
|
|
708
717
|
continue;
|
|
709
718
|
}
|
|
710
719
|
|
|
711
|
-
if (!executeValidator(validatorFunctions, validatorFunctions[validator], validators[validator], element)) {
|
|
720
|
+
if (!executeValidator(validatorFunctions, validatorFunctions[validator], validators[validator], $element)) {
|
|
712
721
|
return false;
|
|
713
722
|
}
|
|
714
723
|
}
|
|
@@ -716,11 +725,11 @@
|
|
|
716
725
|
return true;
|
|
717
726
|
};
|
|
718
727
|
|
|
719
|
-
var isMarkedForDestroy = function isMarkedForDestroy(element) {
|
|
720
|
-
if (element.attr('name').search(/\[([^\]]*?)\]$/) >= 0) {
|
|
721
|
-
var destroyInputName = element.attr('name').replace(/\[([^\]]*?)\]$/, '[_destroy]');
|
|
728
|
+
var isMarkedForDestroy = function isMarkedForDestroy($element) {
|
|
729
|
+
if ($element.attr('name').search(/\[([^\]]*?)\]$/) >= 0) {
|
|
730
|
+
var destroyInputName = $element.attr('name').replace(/\[([^\]]*?)\]$/, '[_destroy]');
|
|
722
731
|
|
|
723
|
-
if (
|
|
732
|
+
if (jQuery__default["default"]("input[name=\"".concat(destroyInputName, "\"]")).val() === '1') {
|
|
724
733
|
return true;
|
|
725
734
|
}
|
|
726
735
|
}
|
|
@@ -728,28 +737,28 @@
|
|
|
728
737
|
return false;
|
|
729
738
|
};
|
|
730
739
|
|
|
731
|
-
var executeAllValidators = function executeAllValidators(element, validators) {
|
|
732
|
-
if (element.data('changed') === false || element.prop('disabled')) {
|
|
740
|
+
var executeAllValidators = function executeAllValidators($element, validators) {
|
|
741
|
+
if ($element.data('changed') === false || $element.prop('disabled')) {
|
|
733
742
|
return;
|
|
734
743
|
}
|
|
735
744
|
|
|
736
|
-
element.data('changed', false);
|
|
745
|
+
$element.data('changed', false);
|
|
737
746
|
|
|
738
|
-
if (executeValidators(ClientSideValidations.validators.all(), element, validators)) {
|
|
739
|
-
passElement(element);
|
|
747
|
+
if (executeValidators(ClientSideValidations.validators.all(), $element, validators)) {
|
|
748
|
+
passElement($element);
|
|
740
749
|
}
|
|
741
750
|
};
|
|
742
751
|
|
|
743
|
-
var validateElement = function validateElement(element, validators) {
|
|
744
|
-
element.trigger('element:validate:before.ClientSideValidations');
|
|
752
|
+
var validateElement = function validateElement($element, validators) {
|
|
753
|
+
$element.trigger('element:validate:before.ClientSideValidations');
|
|
745
754
|
|
|
746
|
-
if (isMarkedForDestroy(element)) {
|
|
747
|
-
passElement(element);
|
|
755
|
+
if (isMarkedForDestroy($element)) {
|
|
756
|
+
passElement($element);
|
|
748
757
|
} else {
|
|
749
|
-
executeAllValidators(element, validators);
|
|
758
|
+
executeAllValidators($element, validators);
|
|
750
759
|
}
|
|
751
760
|
|
|
752
|
-
return afterValidate(element);
|
|
761
|
+
return afterValidate($element);
|
|
753
762
|
};
|
|
754
763
|
|
|
755
764
|
if (!window.ClientSideValidations) {
|
|
@@ -770,4 +779,4 @@
|
|
|
770
779
|
|
|
771
780
|
return ClientSideValidations;
|
|
772
781
|
|
|
773
|
-
}))
|
|
782
|
+
}));
|
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: 19.1.1
|
|
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-11-15 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rails
|
|
@@ -17,7 +17,7 @@ dependencies:
|
|
|
17
17
|
requirements:
|
|
18
18
|
- - ">="
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
|
-
version: 5.
|
|
20
|
+
version: '5.2'
|
|
21
21
|
- - "<"
|
|
22
22
|
- !ruby/object:Gem::Version
|
|
23
23
|
version: '7.0'
|
|
@@ -27,7 +27,7 @@ dependencies:
|
|
|
27
27
|
requirements:
|
|
28
28
|
- - ">="
|
|
29
29
|
- !ruby/object:Gem::Version
|
|
30
|
-
version: 5.
|
|
30
|
+
version: '5.2'
|
|
31
31
|
- - "<"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '7.0'
|
|
@@ -51,14 +51,14 @@ dependencies:
|
|
|
51
51
|
requirements:
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '2.
|
|
54
|
+
version: '2.4'
|
|
55
55
|
type: :development
|
|
56
56
|
prerelease: false
|
|
57
57
|
version_requirements: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '2.
|
|
61
|
+
version: '2.4'
|
|
62
62
|
- !ruby/object:Gem::Dependency
|
|
63
63
|
name: byebug
|
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -73,20 +73,6 @@ dependencies:
|
|
|
73
73
|
- - "~>"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
75
|
version: '11.1'
|
|
76
|
-
- !ruby/object:Gem::Dependency
|
|
77
|
-
name: coveralls_reborn
|
|
78
|
-
requirement: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - "~>"
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: 0.20.0
|
|
83
|
-
type: :development
|
|
84
|
-
prerelease: false
|
|
85
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - "~>"
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: 0.20.0
|
|
90
76
|
- !ruby/object:Gem::Dependency
|
|
91
77
|
name: m
|
|
92
78
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -121,14 +107,14 @@ dependencies:
|
|
|
121
107
|
requirements:
|
|
122
108
|
- - "~>"
|
|
123
109
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: '1.
|
|
110
|
+
version: '1.13'
|
|
125
111
|
type: :development
|
|
126
112
|
prerelease: false
|
|
127
113
|
version_requirements: !ruby/object:Gem::Requirement
|
|
128
114
|
requirements:
|
|
129
115
|
- - "~>"
|
|
130
116
|
- !ruby/object:Gem::Version
|
|
131
|
-
version: '1.
|
|
117
|
+
version: '1.13'
|
|
132
118
|
- !ruby/object:Gem::Dependency
|
|
133
119
|
name: rake
|
|
134
120
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -144,95 +130,33 @@ dependencies:
|
|
|
144
130
|
- !ruby/object:Gem::Version
|
|
145
131
|
version: '13.0'
|
|
146
132
|
- !ruby/object:Gem::Dependency
|
|
147
|
-
name:
|
|
148
|
-
requirement: !ruby/object:Gem::Requirement
|
|
149
|
-
requirements:
|
|
150
|
-
- - "~>"
|
|
151
|
-
- !ruby/object:Gem::Version
|
|
152
|
-
version: '1.9'
|
|
153
|
-
type: :development
|
|
154
|
-
prerelease: false
|
|
155
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
156
|
-
requirements:
|
|
157
|
-
- - "~>"
|
|
158
|
-
- !ruby/object:Gem::Version
|
|
159
|
-
version: '1.9'
|
|
160
|
-
- !ruby/object:Gem::Dependency
|
|
161
|
-
name: rubocop-minitest
|
|
162
|
-
requirement: !ruby/object:Gem::Requirement
|
|
163
|
-
requirements:
|
|
164
|
-
- - "~>"
|
|
165
|
-
- !ruby/object:Gem::Version
|
|
166
|
-
version: 0.10.3
|
|
167
|
-
type: :development
|
|
168
|
-
prerelease: false
|
|
169
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
170
|
-
requirements:
|
|
171
|
-
- - "~>"
|
|
172
|
-
- !ruby/object:Gem::Version
|
|
173
|
-
version: 0.10.3
|
|
174
|
-
- !ruby/object:Gem::Dependency
|
|
175
|
-
name: rubocop-performance
|
|
176
|
-
requirement: !ruby/object:Gem::Requirement
|
|
177
|
-
requirements:
|
|
178
|
-
- - "~>"
|
|
179
|
-
- !ruby/object:Gem::Version
|
|
180
|
-
version: '1.9'
|
|
181
|
-
type: :development
|
|
182
|
-
prerelease: false
|
|
183
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
184
|
-
requirements:
|
|
185
|
-
- - "~>"
|
|
186
|
-
- !ruby/object:Gem::Version
|
|
187
|
-
version: '1.9'
|
|
188
|
-
- !ruby/object:Gem::Dependency
|
|
189
|
-
name: rubocop-rails
|
|
133
|
+
name: simplecov
|
|
190
134
|
requirement: !ruby/object:Gem::Requirement
|
|
191
135
|
requirements:
|
|
192
136
|
- - "~>"
|
|
193
137
|
- !ruby/object:Gem::Version
|
|
194
|
-
version:
|
|
138
|
+
version: 0.21.2
|
|
195
139
|
type: :development
|
|
196
140
|
prerelease: false
|
|
197
141
|
version_requirements: !ruby/object:Gem::Requirement
|
|
198
142
|
requirements:
|
|
199
143
|
- - "~>"
|
|
200
144
|
- !ruby/object:Gem::Version
|
|
201
|
-
version:
|
|
145
|
+
version: 0.21.2
|
|
202
146
|
- !ruby/object:Gem::Dependency
|
|
203
|
-
name:
|
|
147
|
+
name: simplecov-lcov
|
|
204
148
|
requirement: !ruby/object:Gem::Requirement
|
|
205
149
|
requirements:
|
|
206
150
|
- - "~>"
|
|
207
151
|
- !ruby/object:Gem::Version
|
|
208
|
-
version: 0.
|
|
152
|
+
version: 0.8.0
|
|
209
153
|
type: :development
|
|
210
154
|
prerelease: false
|
|
211
155
|
version_requirements: !ruby/object:Gem::Requirement
|
|
212
156
|
requirements:
|
|
213
157
|
- - "~>"
|
|
214
158
|
- !ruby/object:Gem::Version
|
|
215
|
-
version: 0.
|
|
216
|
-
- !ruby/object:Gem::Dependency
|
|
217
|
-
name: simplecov
|
|
218
|
-
requirement: !ruby/object:Gem::Requirement
|
|
219
|
-
requirements:
|
|
220
|
-
- - ">="
|
|
221
|
-
- !ruby/object:Gem::Version
|
|
222
|
-
version: 0.18.5
|
|
223
|
-
- - "<"
|
|
224
|
-
- !ruby/object:Gem::Version
|
|
225
|
-
version: '0.22'
|
|
226
|
-
type: :development
|
|
227
|
-
prerelease: false
|
|
228
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
229
|
-
requirements:
|
|
230
|
-
- - ">="
|
|
231
|
-
- !ruby/object:Gem::Version
|
|
232
|
-
version: 0.18.5
|
|
233
|
-
- - "<"
|
|
234
|
-
- !ruby/object:Gem::Version
|
|
235
|
-
version: '0.22'
|
|
159
|
+
version: 0.8.0
|
|
236
160
|
- !ruby/object:Gem::Dependency
|
|
237
161
|
name: sqlite3
|
|
238
162
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -335,6 +259,7 @@ homepage: https://github.com/DavyJonesLocker/client_side_validations
|
|
|
335
259
|
licenses:
|
|
336
260
|
- MIT
|
|
337
261
|
metadata:
|
|
262
|
+
rubygems_mfa_required: 'true'
|
|
338
263
|
bug_tracker_uri: https://github.com/DavyJonesLocker/client_side_validations/issues
|
|
339
264
|
changelog_uri: https://github.com/DavyJonesLocker/client_side_validations/blob/main/CHANGELOG.md
|
|
340
265
|
source_code_uri: https://github.com/DavyJonesLocker/client_side_validations
|
|
@@ -346,14 +271,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
346
271
|
requirements:
|
|
347
272
|
- - ">="
|
|
348
273
|
- !ruby/object:Gem::Version
|
|
349
|
-
version: '2.
|
|
274
|
+
version: '2.5'
|
|
350
275
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
351
276
|
requirements:
|
|
352
277
|
- - ">="
|
|
353
278
|
- !ruby/object:Gem::Version
|
|
354
279
|
version: '0'
|
|
355
280
|
requirements: []
|
|
356
|
-
rubygems_version: 3.1.
|
|
281
|
+
rubygems_version: 3.1.6
|
|
357
282
|
signing_key:
|
|
358
283
|
specification_version: 4
|
|
359
284
|
summary: Client Side Validations
|