<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 中单独位置的单选按钮组

      Radio Button group in separate place in yii2(yii2 中单独位置的单选按钮组)

        <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 中单独位置的单选按钮组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                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>