There is a RadioList and if at least one of the items is disabled, the client validation does not work at all.
Although there are other choice items.
Example code:
<?php echo $form->field($orderForm, 'payment_type_id')->radioList(\yii\helpers\ArrayHelper::map($paymentTypes, 'id', 'title'), [
'item' => function ($index, $label, $name, $checked, $value) use ($paymentTypes) {
$disabled = $paymentTypes[$index]->status == 0 ? true : false;
return "<label>" . Html::radio($name, $checked, ['value' => $value, 'disabled' => $disabled]) . $label . "</label>";
}
])->label(false); ?>
Clent validating must validate an items, that are not disabled.
Temporary solution: forbidden clicking on an disabled item of radiolist.
| Q | A
| ---------------- | ---
| Yii version | 2.0.22
| PHP version | 7.2.6
| Operating system | CentOS7
$.is(':disabled') will return true if any of the elements in it are disabled.
yii.activeForm.js#L330
Maybe we should check all elements, e.g.
var disabled = true;
$('input').each(function() {
disabled = disabled && $(this).is(':disabled');
});
if (disabled) {
return true;
}
Using reduce
const disabled = $input.toArray().reduce((result, next) => result && $(next).is(':disabled'), true);
if (disabled) {
return true;
}
I can do a PR but I'm not familiar with JS tests.