即使未选中,yii2 表单向导复选框字段值也设置为 1 [英] yii2 formwizard checkbox field value set to 1 even if not selected
问题描述
我正在使用 yii2-formwizard
并且我想在表格步骤中插入一个 checkbox
作为字段 is_legal
的表单输入字段.所以在 fieldConfig
数组中,阅读文档,我插入了以下代码:
I am using yii2-formwizard
and I want to insert a checkbox
as form input field for the field is_legal
in a tabular step. So in fieldConfig
array, reading the documentation, I inserted the following code:
'is_legal' => [
'options' => [
'type' => 'checkbox',
'template' => '{input}{beginLabel}{labelTitle}{endLabel}{error}{hint}',
],
'labelOptions' => ['label' => \Yii::t('app', 'Legal Representative')],
],
如果我选择复选框与否,该字段的值始终为 1
,如下所示:.
If I select the checkbox or not the value of the field is always 1
as shown on: .
但是,当我添加模型的另一个实例时,在预览步骤中,我将 NA
作为 legal代表
字段的值:
However, when I add another instance of the model, in the preview step I have NA
as value of the legal representative
field :
推荐答案
是的,你说得对.即使未选中复选框,它也会错误地显示该值我已更新该部分并添加了 修复.
Yes, you are correct about it. It incorrectly shows the value even if the check box is not checked i have updated the section and added a fix.
//check if single checkbox input
if (inputType.attr("type") == 'checkbox') {
return inputType.is(":checked") ? inputType.val() : '';
}
要获得最新的代码,您需要重复运行 composer 的步骤,
To get the latest code you need to repeat the steps for running composer using,
composer update
清除浏览器缓存,同时清除web
目录中的assets
文件夹.
and clear the browser cache along with clearing the assets
folder in the web
directory.
通常,当我在本地使用扩展程序时,或者如果包含 javascript 更新的扩展程序有更新,我会在本地配置文件中的 components
数组下添加以下设置,以处理获取每次刷新浏览器或重新加载页面时,都会将最新文件和资产强制复制到 web/assets/
目录.
Normally when i am working locally with extensions or if there is an update for an extension which includes javascript updates i add the following settings under the components
array in my local config file that takes care of getting the latest files from, and the assets are force copied every time to the web/assets/
directory whenever you refresh the browser or the page reloads.
'components'=>[
'assetManager' => [
'forceCopy' => true,
],
]
注意:不要让它在实时网站上保持打开状态,因为这会使页面加载速度变慢.
这篇关于即使未选中,yii2 表单向导复选框字段值也设置为 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!