Reputation: 780
I'm trying to use multiple "radioList" fields that have equal values, but when using equal values they do not appear.
In my example, the value is the score and the label is the name of the item.
See the code:
<?= $form->field($model, 'item_bacen')->radioList([
15 => 'NÃO HÁ REGISTROS DE INADIPLENCIA',
-6 => 'HÁ HISTORICO DE DÍVIDA VENCIDA',
0 => 'HISTÓRICO DE RENEGOCIAÇÃO',
0 => 'DÍVIDA VENCIDA NA DATABASE ATUAL',
0 => 'REGISTRO DE PREJUÍZO',
]) ?>
Note that I have 5 options and 3 have the same value.
Here's how it looks:
UPDATED - It worked like this:
<?= $form->field($model, 'item_bacen')->radio(['label' => 'NÃO HÁ REGISTROS DE INADIPLENCIA', 'value' => 15, 'uncheck' => null]) ?>
<?= $form->field($model, 'item_bacen')->radio(['label' => 'HÁ HISTORICO DE DÍVIDA VENCIDA', 'value' => -6, 'uncheck' => null]) ?>
<?= $form->field($model, 'item_bacen')->radio(['label' => 'HISTÓRICO DE RENEGOCIAÇÃO', 'value' => 0, 'uncheck' => null]) ?>
<?= $form->field($model, 'item_bacen')->radio(['label' => 'DÍVIDA VENCIDA NA DATABASE ATUAL', 'value' => 0, 'uncheck' => null]) ?>
<?= $form->field($model, 'item_bacen')->radio(['label' => 'REGISTRO DE PREJUÍZO', 'value' => 0, 'uncheck' => null]) ?>
Upvotes: 0
Views: 665
Reputation: 18021
It's not possible to do what you need using the radioList
activeRecord widget because options are passed as array and you can not have same array keys with different values (last one always overwrites previous keys).
You can write HTML forming this field on your own in the view or pass the options using different unique keys and then when the value is received map it to the one you need like:
<?= $form->field($model, 'item_bacen')->radioList([
0 => 'NÃO HÁ REGISTROS DE INADIPLENCIA',
1 => 'HÁ HISTORICO DE DÍVIDA VENCIDA',
2 => 'HISTÓRICO DE RENEGOCIAÇÃO',
3 => 'DÍVIDA VENCIDA NA DATABASE ATUAL',
4 => 'REGISTRO DE PREJUÍZO',
]) ?>
And on the receiving end something like:
switch ($model->item_bacen) {
case 0:
$model->item_bacen = 15;
break;
case 1:
$model->item_bacen = -6;
break;
case 2:
case 3:
case 4:
$model->item_bacen = 0;
break;
}
Upvotes: 1