From 2650948e87b230c1f706d5bdd7c28b4ae68edc81 Mon Sep 17 00:00:00 2001 From: Toir Tuychiev Date: Thu, 1 Apr 2021 03:13:53 +0500 Subject: [PATCH] Fix #18323: Fix client validation of RadioList when there are disabled items --- .gitignore | 1 + framework/CHANGELOG.md | 1 + framework/assets/yii.activeForm.js | 3 ++- tests/js/data/yii.activeForm.html | 15 ++++++++++++++- tests/js/tests/yii.activeForm.test.js | 25 +++++++++++++++++++------ 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 769d405..02326c0 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,4 @@ phpunit.phar # NPM packages /node_modules .env +package-lock.json diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 2b8e3b0..c34390a 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.42 under development ------------------------ +- Bug #18323: Fix client validation of RadioList when there are disabled items (toir427) - Enh #18534: Added `prepareSearchQuery` property in `yii\rest\IndexAction` (programmis) - Enh #18566: Throw the original exception when `yii\web\Controller::bindInjectedParams()` catches HttpException (pigochu) - Bug #18574: Fix `yii\web\DbSession` to use the correct db if strict mode is used (Mignar) diff --git a/framework/assets/yii.activeForm.js b/framework/assets/yii.activeForm.js index 34d3346..c61df82 100644 --- a/framework/assets/yii.activeForm.js +++ b/framework/assets/yii.activeForm.js @@ -329,7 +329,8 @@ this.$form = $form; var $input = findInput($form, this); - if ($input.is(':disabled')) { + var disabled = $input.toArray().reduce((result, next) => result && $(next).is(':disabled'), true); + if (disabled) { return true; } // validate markup for select input diff --git a/tests/js/data/yii.activeForm.html b/tests/js/data/yii.activeForm.html index 928b253..d44c9f1 100644 --- a/tests/js/data/yii.activeForm.html +++ b/tests/js/data/yii.activeForm.html @@ -34,4 +34,17 @@
- \ 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 50582b5..1667123 100644 --- a/tests/js/tests/yii.activeForm.test.js +++ b/tests/js/tests/yii.activeForm.test.js @@ -104,6 +104,19 @@ describe('yii.activeForm', function () { } } }); + + describe('if at least one of the items is disabled', function () { + it('validate radioList', function () { + $activeForm = $('#w2'); + $activeForm.yiiActiveForm({ + id: 'radioList', + input: '#radioList' + }); + $activeForm.yiiActiveForm('validate'); + + assert.isFalse($activeForm.data('yiiActiveForm').validated); + }); + }); }); describe('resetForm method', function () { @@ -228,12 +241,12 @@ describe('yii.activeForm', function () { $input = $('#' + inputId); $activeForm = $('#w0'); - $activeForm.yiiActiveForm( - [{ - "id": inputId, - "name": "name", - input: '#' + inputId - }], []).on('afterValidate', afterValidateSpy); + $activeForm.yiiActiveForm( + [{ + "id": inputId, + "name": "name", + input: '#' + inputId + }], []).on('afterValidate', afterValidateSpy); $activeForm.yiiActiveForm('validate'); assert.notEqual(null, eventData);