Yii2: RadioList Client validation bug

Created on 30 Sep 2019  路  3Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

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); ?>

What is the expected result?

Clent validating must validate an items, that are not disabled.

What do you get instead?

Temporary solution: forbidden clicking on an disabled item of radiolist.

Additional info

| Q | A
| ---------------- | ---
| Yii version | 2.0.22
| PHP version | 7.2.6
| Operating system | CentOS7

hacktoberfest help wanted ready for adoption bug

All 3 comments

$.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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sobit picture sobit  路  3Comments

chaintng picture chaintng  路  3Comments

SamMousa picture SamMousa  路  3Comments

jpodpro picture jpodpro  路  3Comments

indicalabs picture indicalabs  路  3Comments