RadioList return empty value in all radio except last

Hi

I’m trying do a table like below. I have one value and one radio button per column, what’s happening is, when i select the first or next radio buttons (except the last) return a empty value. (can u see above).

I plan to make a table:


<tr>

<td>text and radio 1 & name</td>

<td>text and radio 1 & name</td>

<td>text and radio 1 & name</td>

</tr>

My code:

Controller:


$job = new Job;

$type = Type::find()->all();


var_dump(Yii::$app->request->post('Job'));

View:


foreach($type as $value){

    {

        echo '<td>';

            echo $value->text;

            echo $form->field($job, "Type_Id")->radioList([$value->Id => $value->Name], ['class'=>'text-muted'])->label(false);

        echo '</td>';

    }

}

var_dump return:

If i select first or each others radio (except last):


'Type_Id' => string '' (length=0)

If i select last radio:


'Type_Id' => string '20' (length=2)

HTML Generated:


<div class="form-group field-job-Type_Id">

<input type="hidden" name="Job[Type_Id]" value=""><div id="job-Type_Id" class="text-muted"><label><input type="radio" name="Job[Type_Id]" value="14"> Blue </label></div>

<div class="help-block"></div>

</div>


<div class="form-group field-job-Type_Id">

<input type="hidden" name="Job[Type_Id]" value=""><div id="job-Type_Id" class="text-muted"><label><input type="radio" name="Job[Type_Id]" value="18"> Red </label></div>

<div class="help-block"></div>

</div>


<div class="form-group field-job-Type_Id">

<input type="hidden" name="Job[Type_Id]" value=""><div id="job-Type_Id" class="text-muted"><label><input type="radio" name="Job[Type_Id]" value="20"> Purple </label></div>

<div class="help-block"></div>

</div>

Thank you

You should not use "radioList()" here. Try to use "radio()" instead. http://www.yiiframework.com/doc-2.0/yii-widgets-activefield.html#radio()-detail




foreach($type as $value){

    echo '<td>';

    echo $form->field($job, "Type_Id")->radio(['label' => $value->Name, 'value' => $value->Id]);

    echo '</td>';

}



Thank for your reply.

But the same problem happens, only change empty string to 0…

If i select first or each others radio (except last):


'Type_Id' => string '0' (length=0)

If i select last radio:


'Type_Id' => string '20' (length=2)

Would you please show your view code and the controller code?

Problem solved adding:


'uncheck' => null


 $form->field($job, "Type_Id")->radio(['label' => $job->Name, 'value' => $job->Id, 'uncheck' => null]);

Thank you

Congrats!