Closed RookieLittle closed 6 years ago
hi @RookieLittle , Inspect Element make difference code, please screen-shot from source code (View Page Source in Firefox ). maybe this snippet code help you :
<?= $form->field($model, 'color')->radioList(
["white"=> "White", "blue"=> 'Blue', "red"=> 'Red',"black"=> 'Black'],
[
'item' => function($index, $label, $name, $checked, $value) {
$return = '<label class="modal-radio">';
/* ----->*/ if($checked ) $return .= '<input checked type="radio" name="' . $name . '"value="' . $value . '" tabindex="3">';
/* ----->*/ else $return .= '<input type="radio" name="' . $name . '"value="' . $value . '" tabindex="3">';
$return .= '<i ></i>';
$return .= '<span style="background: '. $value .'">'. ucwords($label) . '</span>';
$return .= '</label>';
return $return;
}
]
) ?>
"checked" is automatically removed from template in method _parseTemplate
in yii2-dynamic-form.js
.
Comment out the following lines, to see it in action:
if ($inputHidden && count === 1) {
$(this).val(1);
$inputHidden.val(0);
}
$(this).prop('checked', false);
This should work in most cases to preselect values on create. On update, this will not work properly, because the first element will be cloned and therefore the selected value of the first element will be selected in the clone too (hence the general deletion of preselections as a default behavior). However you can just add some jquery expressions tailored to your specifications etc. in a method beeing called on add Item (restorespecialjs e.g.) which selects the new clone and always gets the desired radio checked
in the picture below is update view the radio button is not checked in the display,
but when u inspect element u will found that it actually checked (like the picture below).
it only happened on radio list the dropdown list is work perfectly, anyone have the same issue or anyone did use the radiolist but it dont have such issue?