yii2 formwizard 复选框字段值设置为 1,即使未选中

yii2 formwizard checkbox field value set to 1 even if not selected

我正在使用 yii2-formwizard,我想在表格步骤中插入一个 checkbox 作为字段 is_legal 的表单输入字段。所以在 fieldConfig 数组中,阅读文档,我插入了以下代码:

'is_legal' => [
    'options' => [
        'type' => 'checkbox',
        'template' => '{input}{beginLabel}{labelTitle}{endLabel}{error}{hint}',
    ],
    'labelOptions' => ['label' => \Yii::t('app', 'Legal Representative')],
],

如果我 select 复选框,则该字段的值始终是 1,如上所示:

但是,当我添加模型的另一个实例时,在预览步骤中我将 NA 作为 legal representative 字段的值:

是的,你说得对。即使未选中该复选框,它也会错误地显示该值我已经更新了该部分并添加了 fix

//check if single checkbox input

if (inputType.attr("type") == 'checkbox') {
    return inputType.is(":checked") ? inputType.val() : '';
}

要获取最新代码,您需要使用 运行 composer 重复这些步骤,

composer update

并清除浏览器缓存以及清除 web 目录中的 assets 文件夹。

通常当我在本地使用扩展或者如果有包含 javascript 更新的扩展更新时,我会在我的本地配置文件中的 components 数组下添加以下设置注意从中获取最新文件,每次刷新浏览器或重新加载页面时,资产都会被强制复制到 web/assets/ 目录。

'components'=>[
    'assetManager' => [
        'forceCopy' => true,
    ],
]

注意:不要让它在实时站点上打开,因为它会使页面加载速度变慢。