Skip to content

Commit 42c6412

Browse files
committed
Do not validate dynamically disabled inputs
1 parent ff2abef commit 42c6412

File tree

6 files changed

+8
-5
lines changed

6 files changed

+8
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [FEATURE] Do not require `jquery-rails` gem ([#785](https://github.com/DavyJonesLocker/client_side_validations/pull/785))
77
* [FEATURE] Add support for many association validations ([#783](https://github.com/DavyJonesLocker/client_side_validations/pull/783))
88
* [BUGFIX] Fix Rails generators ([#786](https://github.com/DavyJonesLocker/client_side_validations/pull/786))
9+
* [BUGFIX] Do not validate dynamically disabled inputs ([#789](https://github.com/DavyJonesLocker/client_side_validations/pull/789))
910

1011
## 16.2.0 / 2020-04-10
1112

dist/client-side-validations.esm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ var isMarkedForDestroy = function isMarkedForDestroy(element) {
720720
};
721721

722722
var executeAllValidators = function executeAllValidators(element, validators) {
723-
if (element.data('changed') === false) {
723+
if (element.data('changed') === false || element.prop('disabled')) {
724724
return;
725725
}
726726

dist/client-side-validations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@
726726
};
727727

728728
var executeAllValidators = function executeAllValidators(element, validators) {
729-
if (element.data('changed') === false) {
729+
if (element.data('changed') === false || element.prop('disabled')) {
730730
return;
731731
}
732732

src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const isMarkedForDestroy = (element) => {
180180
}
181181

182182
const executeAllValidators = (element, validators) => {
183-
if (element.data('changed') === false) {
183+
if (element.data('changed') === false || element.prop('disabled')) {
184184
return
185185
}
186186

test/javascript/public/test/validateElement.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,11 @@ QUnit.test("Don't validate dynamically disabled inputs", function (assert) {
398398
input_tag: '<div class="field_with_errors"><span id="input_tag"></span><label for="user_name" class="message"></label></div>',
399399
label_tag: '<div class="field_with_errors"><label id="label_tag"></label></div>'
400400
},
401-
validators: { 'user_2[name]': { presence: { message: 'must be present' } } }
401+
validators: { 'user_2[name]': { presence: [{ message: 'must be present' }] } }
402402
}
403403

404404
$('#qunit-fixture')
405+
.html('')
405406
.append($('<form>', {
406407
action: '/users',
407408
'data-client-side-validations': JSON.stringify(dataCsv),
@@ -422,6 +423,7 @@ QUnit.test("Don't validate dynamically disabled inputs", function (assert) {
422423
input.attr('disabled', 'disabled')
423424
input.val('')
424425
input.trigger('focusout')
426+
425427
assert.notOk(input.parent().hasClass('field_with_errors'))
426428
})
427429

vendor/assets/javascripts/rails.validations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@
726726
};
727727

728728
var executeAllValidators = function executeAllValidators(element, validators) {
729-
if (element.data('changed') === false) {
729+
if (element.data('changed') === false || element.prop('disabled')) {
730730
return;
731731
}
732732

0 commit comments

Comments
 (0)