问题
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')],
],
If I select the checkbox or not the value of the field is always 1
as shown on: .
However, when I add another instance of the model, in the preview step I have NA
as value of the legal representative
field :
回答1:
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() : '';
}
To get the latest code you need to repeat the steps for running composer using,
composer update
and clear the browser cache along with clearing the assets
folder in the web
directory.
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,
],
]
Note: Dont leave it open on live site as it would make the page load slower.
来源:https://stackoverflow.com/questions/60207215/yii2-formwizard-checkbox-field-value-set-to-1-even-if-not-selected