<bdo id='AqDEU'></bdo><ul id='AqDEU'></ul>

    1. <tfoot id='AqDEU'></tfoot>

      <small id='AqDEU'></small><noframes id='AqDEU'>

      <i id='AqDEU'><tr id='AqDEU'><dt id='AqDEU'><q id='AqDEU'><span id='AqDEU'><b id='AqDEU'><form id='AqDEU'><ins id='AqDEU'></ins><ul id='AqDEU'></ul><sub id='AqDEU'></sub></form><legend id='AqDEU'></legend><bdo id='AqDEU'><pre id='AqDEU'><center id='AqDEU'></center></pre></bdo></b><th id='AqDEU'></th></span></q></dt></tr></i><div id='AqDEU'><tfoot id='AqDEU'></tfoot><dl id='AqDEU'><fieldset id='AqDEU'></fieldset></dl></div>
      <legend id='AqDEU'><style id='AqDEU'><dir id='AqDEU'><q id='AqDEU'></q></dir></style></legend>

      yii2 中单独位置的单选按钮组

      时间:2023-10-15

        <i id='I49YB'><tr id='I49YB'><dt id='I49YB'><q id='I49YB'><span id='I49YB'><b id='I49YB'><form id='I49YB'><ins id='I49YB'></ins><ul id='I49YB'></ul><sub id='I49YB'></sub></form><legend id='I49YB'></legend><bdo id='I49YB'><pre id='I49YB'><center id='I49YB'></center></pre></bdo></b><th id='I49YB'></th></span></q></dt></tr></i><div id='I49YB'><tfoot id='I49YB'></tfoot><dl id='I49YB'><fieldset id='I49YB'></fieldset></dl></div>

        <small id='I49YB'></small><noframes id='I49YB'>

            <bdo id='I49YB'></bdo><ul id='I49YB'></ul>
            1. <tfoot id='I49YB'></tfoot>
            2. <legend id='I49YB'><style id='I49YB'><dir id='I49YB'><q id='I49YB'></q></dir></style></legend>

                <tbody id='I49YB'></tbody>

                本文介绍了yii2 中单独位置的单选按钮组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                所以,我想在不同的地方有两个单选按钮,我一直在尝试寻找解决方案,每个人都建议使用 radiolist,这在我的情况下是不可能的.

                如果我这样说(work_part_time 按钮):(下)

                <div class="col-sm-2"><?= $form->field($model, 'work_part_time')->radio(['label' => 'yes', 'value' => 1])?></div>-<div class="col-sm-3"><?= $form->field($model, 'hour_week')->textInput(['type' => 'number', 'placeholder' => '小时/周'])->标签(假)?>

                <div class="col-sm-3"><?= $form->field($model, 'part_time_rate')->textInput(['type' => 'number', 'placeholder' => 'rate/hour(SGD)'])->标签(假)?>

                <div class="form-group"><?= $form->field($model, 'work_part_time')->radio( [0 => 'No'])->label('No')?>

                <小时><div class="row"><div class="col-sm-2"><?= $form->field($model, 'work_part_time')->radio(['label' => 'yes', 'value' => 1])?></div>-<div class="col-sm-3"><?= $form->field($model, 'hour_week')->textInput(['type' => 'number', 'placeholder' => '小时/周'])->标签(假)?>

                <div class="col-sm-3"><?= $form->field($model, 'part_time_rate')->textInput(['type' => 'number', 'placeholder' => 'rate/hour(SGD)'])->标签(假)?>

                <div class="form-group"><?= $form->field($model, 'work_part_time')->radio( [0 => 'No'])->label('No')?>

                <小时>

                我只能得到 0 的值.

                有人找到了解决方案吗?

                解决方案

                Yii 将根据存储属性的值为单选按钮分配选中或未选中的值,因此如果值为 0 它将检查按钮值为 0.您的问题似乎是 Yii 自动生成的隐藏输入.正如其他人所建议的,如果您希望同一字段有多个单选按钮,则需要将其设置为 null.

                如果用户选中另一个按钮,则所有其他同名的单选按钮将变为未选中状态.属性名称由 Yii 在创建按钮时自动生成.为您的单选按钮试试这些:

                field($model, 'work_part_time')->radio(['label' => 'Option 1', 'value' => 1, '取消选中' => null]) ?><?= $form->field($model, 'work_part_time')->radio(['label' => 'Option 2', 'value' => 0, 'uncheck' => null]) ?><?= $form->field($model, 'work_part_time')->radio(['label' => 'Option 3', 'value' => 2, 'uncheck' => null]) ?><?= $form->field($model, 'work_part_time')->radio(['label' => 'Option4', 'value' => 3, 'uncheck' => null]) ?>

                每个按钮需要不同的值,这是保存记录时将存储在您的字段中的值.

                只能检查一个按钮,因此如果您有多个具有相同值和相同名称的按钮,就像您在示例中所看到的那样,那么只会检查集合中的最后一个.我不知道有什么办法解决这个问题.我建议您使用 将您的表单拆分为逻辑部分,每个部分都与 work_part_time 是 yes 或 no 相关.你似乎已经开始这样做了!

                So, I want to have two radio button in separate place, I have been trying to search for the solution and everyone suggests to use radiolist which is not possible in my case.

                If I put it like this (work_part_time button) : (below)

                <div class="row">
                    <div class="col-sm-2">
                        <?= $form->field($model, 'work_part_time')->radio(['label' => 'yes', 'value' => 1])?>
                    </div>-
                
                    <div class="col-sm-3">
                        <?= $form->field($model, 'hour_week')->textInput(['type' => 'number', 'placeholder' => 'Hour/Week'])->label(false)?>
                    </div>
                
                    <div class="col-sm-3">
                        <?= $form->field($model, 'part_time_rate')->textInput(['type' => 'number', 'placeholder' => 'rate/hour(SGD)'])->label(false)?> 
                    </div>
                </div>
                
                <div class="form-group">
                    <?= $form->field($model, 'work_part_time')->radio( [0 => 'No'])->label('No')?>
                </div>
                <hr>
                <div class="row">
                    <div class="col-sm-2">
                        <?= $form->field($model, 'work_part_time')->radio(['label' => 'yes', 'value' => 1])?>
                    </div>-
                
                    <div class="col-sm-3">
                        <?= $form->field($model, 'hour_week')->textInput(['type' => 'number', 'placeholder' => 'Hour/Week'])->label(false)?>
                    </div>
                
                    <div class="col-sm-3">
                        <?= $form->field($model, 'part_time_rate')->textInput(['type' => 'number', 'placeholder' => 'rate/hour(SGD)'])->label(false)?> 
                    </div>
                </div>
                
                <div class="form-group">
                    <?= $form->field($model, 'work_part_time')->radio( [0 => 'No'])->label('No')?>
                </div>
                <hr>
                

                I only can get 0 for the value.

                Anyone has found the solution for this?

                解决方案

                Yii will assign a checked or unchecked value to the radio button depending on the value of the stored attribute, so if the value is 0 it will check the button that has the value 0. Your problem seems to have been the hidden input that Yii automatically generates. As others have suggested, you need to set this to null if you want more than one radio button for the same field.

                If the user checks another button, then all other radio buttons with the same name will become unchecked. The name of the attribute is generated automatically by Yii when it creates the button. Try these for your radio buttons:

                <?= $form->field($model, 'work_part_time')->radio(['label' => 'Option 1', 'value' => 1, 'uncheck' => null]) ?>
                <?= $form->field($model, 'work_part_time')->radio(['label' => 'Option 2', 'value' => 0, 'uncheck' => null]) ?>
                <?= $form->field($model, 'work_part_time')->radio(['label' => 'Option 3', 'value' => 2, 'uncheck' => null]) ?>
                <?= $form->field($model, 'work_part_time')->radio(['label' => 'Option4', 'value' => 3, 'uncheck' => null]) ?>
                

                Each button needs a different value, and this is the value that will be stored in your field when the record is saved.

                There can only ever be one button checked, so if you have multiple buttons with the same value, and the same name, as you seem to have in your examples, then only the last one in the set will be checked. I don't know of a way round this. I suggest you use <formgroup> to split up your form into logical sections, each section relating to whether work_part_time is yes or no. You seem to have started doing this!

                这篇关于yii2 中单独位置的单选按钮组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Yii2 $this->registerJs($js);如何在 $js 中传递 php 变量 下一篇:在 Kartik Gridview 数据列中自动换行

                相关文章

                1. <small id='dKxqG'></small><noframes id='dKxqG'>

                    <i id='dKxqG'><tr id='dKxqG'><dt id='dKxqG'><q id='dKxqG'><span id='dKxqG'><b id='dKxqG'><form id='dKxqG'><ins id='dKxqG'></ins><ul id='dKxqG'></ul><sub id='dKxqG'></sub></form><legend id='dKxqG'></legend><bdo id='dKxqG'><pre id='dKxqG'><center id='dKxqG'></center></pre></bdo></b><th id='dKxqG'></th></span></q></dt></tr></i><div id='dKxqG'><tfoot id='dKxqG'></tfoot><dl id='dKxqG'><fieldset id='dKxqG'></fieldset></dl></div>

                      <bdo id='dKxqG'></bdo><ul id='dKxqG'></ul>

                    <legend id='dKxqG'><style id='dKxqG'><dir id='dKxqG'><q id='dKxqG'></q></dir></style></legend>
                  1. <tfoot id='dKxqG'></tfoot>