我在yii2中创建了带有问题和多个选项的表格形式。由于名称不同,单选按钮出现问题。无法选择单个正确的选项。
<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创建操作代码
<?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; ?>