You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I have write a DictValidator for yii2, so I Inject a dict() function in yii.validation.js and so it can check the value is ok. it work well on any other input except the checkbox, so I review the yii.activeForm.js, and i find the bug.
this is now code of function yii.activeForm.js:
var getValue = function ($form, attribute) {
var $input = findInput($form, attribute);
var type = $input.attr('type');
if (type === 'checkbox' || type === 'radio') {
var $realInput = $input.filter(':checked');
if (!$realInput.length) {
$realInput = $form.find('input[type=hidden][name="' + $input.attr('name') + '"]');
}
return$realInput.val();
} else {
return$input.val();
}
};
if type == 'checkbox', we may expect the function return an array of value, but it return a string。this is an example:
step1:
I put a checkbox group on the page, and set a js block
step 2 : I click the button, and see the result:
the getValue should return ["上海", "广州"], but the return is "上海"
I fixed the code like this, and it works well:
var getValue = function ($form, attribute) {
var $input = findInput($form, attribute);
var type = $input.attr('type');
if (type === 'checkbox' || type === 'radio') {
var $realInput = $input.filter(':checked');
if (!$realInput.length) {
$realInput = $form.find('input[type=hidden][name="' + $input.attr('name') + '"]');
}
if(type === 'checkbox') {
var ret = [];
$realInput.each(function(){
ret.push($(this).val());
});
return ret;
}
return$realInput.val();
} else {
return$input.val();
}
};
Additional info
Q
A
Yii version
2.0.15
PHP version
7.1.20
Operating system
centos
The text was updated successfully, but these errors were encountered:
Hello, I have write a DictValidator for yii2, so I Inject a dict() function in yii.validation.js and so it can check the value is ok. it work well on any other input except the checkbox, so I review the yii.activeForm.js, and i find the bug.
this is now code of function yii.activeForm.js:
if type == 'checkbox', we may expect the function return an array of value, but it return a string。this is an example:
step1:
I put a checkbox group on the page, and set a js block
step 2 : I click the button, and see the result:
the getValue should return ["上海", "广州"], but the return is "上海"
I fixed the code like this, and it works well:
Additional info
The text was updated successfully, but these errors were encountered: