I created a tabular form in yii2 with question and multiple options. Getting issue with radio button due to different name. Not able to select single correct option.

<input type="radio" id="tbloptions-0-correct" name="Tbloptions[0][correct]" value="1" checked="" aria-invalid="false">
<input type="radio" id="tbloptions-1-correct" name="Tbloptions[1][correct]" value="1" checked="">

Yii2 create action code

    <?php foreach ($modelOptions as $i => $modelOption): ?>
        <div class="item panel panel-default"><!-- widgetBody -->
            <div class="panel-heading">
                <h3 class="panel-title pull-left">Option</h3>
                <div class="pull-right">
                    <button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
                    <button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="panel-body">
                <div class="row">
                     <div class="col-md-1">
                        <?= $form->field($modelOption, "[{$i}]correct")->radio(['label'=>false]) ?>
                     </div>
                     <div class="col-md-6">
                        <?= $form->field($modelOption, "[{$i}]options")->textArea()->label(false) ?>
                     </div>
                </div>
            </div>
        </div>
    <?php endforeach; ?>

Snapshot given below - enter image description here

0 Answers