yiisoft / yii2-bootstrap4

Yii 2 Bootstrap 4 Extension
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
216 stars 106 forks source link

ActiveField radioList item rewritten #53

Closed ghost closed 5 years ago

ghost commented 6 years ago

What steps will reproduce the problem?

<?php $form = ActiveForm::begin([
    'id' => 'form-step',
    'layout' => 'horizontal',
    **'fieldClass' => 'yii\bootstrap4\ActiveField',**
    'fieldConfig' => [
        'options' => ['class' => 'form-group row'],
        'horizontalCssClasses' => [
            'label' => 'col-lg-6',
            'error' => 'invalid-tooltip row px-3',
            'wrapper' => 'col-lg-6 position-relative',
         ],
    ],
    'options' => ['class' => 'pr-md-3 pr-lg-0 w-100'],
]) ?>
<?= $form->field($model, 'type', ['horizontalCssClasses' => ['wrapper' => 'col-xl-8 col-lg-10 position-relative']])->radioList(ArrayHelper::map($model->getTypeProject(), 'value', 'name'), [
    'class' => 'px-3 row',
    'aria-expanded' => 'true',
    'role' => 'listbox',
    **'item' => function** ($index, $label, $name, $checked, $value){
        switch ($index) {
            case 0:
                $checked = ' checked';
                $icon = Yii::$app->params['icon_equip'];
                break;
            case 1:
                $icon = Yii::$app->params['icon_mobile'];
                break;
            case 2:
                $icon = Yii::$app->params['icon_target'];
                break;
            case 3:
                $icon = Yii::$app->params['icon_speaker'];
                break;
            case 4:
                $icon = Yii::$app->params['icon_tower'];
                break;
            case 5:
                $icon = Yii::$app->params['icon_program'];
                break;
            default:
                $icon = false;
        }
        $return = "<div class='col-6 col-sm-4 px-0'>";
        $return .= "<input id='type-{$index}' type='radio' class='d-none check-type' name='{$name}' value='{$value}'" . $checked . ">";
        $return .= "<label for='type-{$index}' class='d-flex flex-column h-100 justify-content-center p-4 w-100'>";
        $return .= "<span class='mb-4'>{$icon}</span>";
        $return .= "<span class='corner'>{$label}</span>";
        $return .= '</label>';
        return .= "</div>";

        return $return;
    },
])->label(false) ?>

What's expected?

<div class="form-check">
<input type="radio" id="i0" class="form-check-input" name="AppForm[type]" value="0">
<label class="form-check-label" for="i0">123</label>
</div>

What do you get instead?

<div class="col-6 col-sm-4 px-0">
<input id="type-0" type="radio" class="d-none check-type" name="AppForm[type]" value="0" checked="">
<label for="type-0" class="d-flex flex-column h-100 justify-content-center p-4 w-100">
<span class="mb-4"><svg></svg></span>
<span class="corner">123</span>
</label>
</div>

Additional info

Q A
Yii vesion 2.0.16-dev
PHP version 7.2.8
Operating system Windows 10
simialbi commented 6 years ago

May you have confused expected with get instead?