From cfe0bf5cf1eb49401f6e6116b57a6ab5a9acdb7b Mon Sep 17 00:00:00 2001 From: Evgeniy Moiseenko Date: Fri, 19 Oct 2018 01:26:40 +0300 Subject: [PATCH] Fixes #14039, fixes #16636: Fixed validation for disabled inputs --- framework/CHANGELOG.md | 1 + framework/assets/yii.activeForm.js | 6 +++--- tests/js/data/yii.activeForm.html | 34 ++++++++++++++++++++++++++++++++++ tests/js/tests/yii.activeForm.test.js | 26 ++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 6baaf9f..6b25db9 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.16 under development ------------------------ +- Bug #14039, #16636: Fixed validation for disabled inputs (s1lver, omzy83) - Bug #16425: Check for additional values for disabled confirm dialog (Alex-Code, s1lver) - Enh #14367: In `yii\db\mysql\QueryBuilder` added support fractional seconds for time types for MySQL >= 5.6.4 (konstantin-vl) - Bug #16766: `yii\filters\ContentNegotiator` was not setting `Vary` header to inform cache recipients (koteq, cebe, samdark) diff --git a/framework/assets/yii.activeForm.js b/framework/assets/yii.activeForm.js index ec0be1e..fbcece4 100644 --- a/framework/assets/yii.activeForm.js +++ b/framework/assets/yii.activeForm.js @@ -325,7 +325,7 @@ // client-side validation $.each(data.attributes, function () { this.$form = $form; - if (!$(this.input).is(":disabled")) { + if (!findInput($form, this).is(":disabled")) { this.cancelled = false; // perform validation only if the form is being submitted or if an attribute is pending validation if (data.submitting || this.status === 2 || this.status === 3) { @@ -489,7 +489,6 @@ updateInput($(this), attribute, msg); } } - }; var watchAttribute = function ($form, attribute) { @@ -625,8 +624,9 @@ if (submitting) { var errorAttributes = []; + var $input = findInput($form, this); $.each(data.attributes, function () { - if (!$(this.input).is(":disabled") && !this.cancelled && updateInput($form, this, messages)) { + if (!$input.is(":disabled") && !this.cancelled && updateInput($form, this, messages)) { errorAttributes.push(this); } }); diff --git a/tests/js/data/yii.activeForm.html b/tests/js/data/yii.activeForm.html index 912c549..928b253 100644 --- a/tests/js/data/yii.activeForm.html +++ b/tests/js/data/yii.activeForm.html @@ -1,3 +1,37 @@
+ +
+
+
+ + +
+
+
+ +
+
+ + +
+ + +
+
+
+
+ +
+
+ + +
+ + +
+
+
+
+
\ No newline at end of file diff --git a/tests/js/tests/yii.activeForm.test.js b/tests/js/tests/yii.activeForm.test.js index 65a5649..23733a5 100644 --- a/tests/js/tests/yii.activeForm.test.js +++ b/tests/js/tests/yii.activeForm.test.js @@ -78,6 +78,32 @@ describe('yii.activeForm', function () { assert.isTrue(afterValidateSpy.calledOnce); }); }); + + describe('with disabled fields', function () { + var inputTypes = { + test_radio: 'radioList', + test_checkbox: 'checkboxList', + test_text: 'text input' + }; + + for (var key in inputTypes) { + if (inputTypes.hasOwnProperty(key)) { + (function () { + var inputId = key; + it(inputTypes[key] + ' disabled field', function () { + $activeForm = $('#w1'); + $activeForm.yiiActiveForm({ + id: inputId, + input: '#' + inputId + }); + $activeForm.yiiActiveForm('validate'); + + assert.isFalse($activeForm.data('yiiActiveForm').validated); + }); + })(); + } + } + }); }); describe('resetForm method', function () {