Skip to content

Commit

Permalink
Fix yiisoft#18323: Fix client validation of RadioList when there are …
Browse files Browse the repository at this point in the history
…disabled items
  • Loading branch information
toir427 authored Mar 31, 2021
1 parent 10bb71a commit 2650948
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ phpunit.phar
# NPM packages
/node_modules
.env
package-lock.json
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion framework/assets/yii.activeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion tests/js/data/yii.activeForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,17 @@
<div class="help-block"></div>
</div>
</fieldset>
</form>
</form>

<form id="w2">
<div class="form-group required">
<label class="control-label">Test radio</label>
<input type="hidden" name="Test[radio]" value="">
<div id="radioList" aria-required="true">
<label><input type="radio" name="Test[radio]" disabled> Test 1</label>
<label><input type="radio" name="Test[radio]"> Test 2</label>
<label><input type="radio" name="Test[radio]"> Test 3</label>
</div>
<div class="help-block"></div>
</div>
</form>
25 changes: 19 additions & 6 deletions tests/js/tests/yii.activeForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2650948

Please sign in to comment.