Browse Source

Fix #8225: Fixed AJAX validation with checkboxList was only triggered on first select

tags/2.0.29
Yuriy Mamaev 5 years ago committed by Alexander Makarov
parent
commit
40fff67aa4
  1. 1
      framework/CHANGELOG.md
  2. 8
      framework/assets/yii.activeForm.js
  3. 22
      tests/js/tests/yii.activeForm.test.js

1
framework/CHANGELOG.md

@ -7,6 +7,7 @@ Yii Framework 2 Change Log
- Bug #17602: `EmailValidator` with `checkDNS=true` throws `ErrorException` on bad domains on Alpine (batyrmastyr)
- Enh #17607: Added Yii version 3 DI config compatibility (hiqsol)
- Bug #17606: Fix error in `AssetBundle` when a disabled bundle with custom init() was still published (onmotion)
- Bug #8225: Fixed AJAX validation with checkboxList was only triggered on first select (execut)
- Bug #17597: PostgreSQL 12 and partitioned tables support (batyrmastyr)
- Bug #17625: Fix boolean `data` attributes from subkeys rendering in `Html::renderTagAttributes()` (brandonkelly)

8
framework/assets/yii.activeForm.js

@ -876,6 +876,14 @@
var type = $input.attr('type');
if (type === 'checkbox' || type === 'radio') {
var $realInput = $input.filter(':checked');
if ($realInput.length > 1) {
var values = [];
$realInput.each(function(index) {
values.push($($realInput.get(index)).val());
});
return values;
}
if (!$realInput.length) {
$realInput = $form.find('input[type=hidden][name="' + $input.attr('name') + '"]');
}

22
tests/js/tests/yii.activeForm.test.js

@ -183,6 +183,28 @@ describe('yii.activeForm', function () {
$activeForm.yiiActiveForm('updateAttribute', inputId);
assert.equal('New value', eventData.value);
});
// https://github.com/yiisoft/yii2/issues/8225
it('the value of the checkboxes must be an array', function () {
var inputId = 'test_checkbox';
var $input = $('#' + inputId);
$activeForm = $('#w1');
$activeForm.yiiActiveForm('destroy');
$activeForm.yiiActiveForm([
{
id: inputId,
input: '#' + inputId
}
]).on('afterValidateAttribute', afterValidateAttributeSpy);
$input.find('input').prop('checked', true);
$activeForm.yiiActiveForm('updateAttribute', inputId);
var value = eventData.value;
assert.isArray(value);
assert.deepEqual(['1', '0'], value);
});
});
describe('afterValidate', function () {

Loading…
Cancel
Save