我卡住了; /我有activeradiolist,并且工作正常,但是我需要创建另一个带有下拉菜单项的列表芽我的代码与$ model为activeradioList
echo Html::activeradioList($add, 'type_contact',
$items, ['item' => function ($index, $label, $name, $checked, $value) {
$return = '<div style="max-height:178px!important;" class="radio col-xs-12 col-lg-6"><input type="radio" name="' . $name . '" value="' . $value . '" tabindex="3" id="' . $name . $index . '" ' . ($checked ? 'checked' : '') . '>';
$return .= '<label style="padding-top:0!important" for="' . $name . $index . '">' . $label . '</label></div>';
if ($checked && $index === 1) {
$return .= '<script>$(document).ready(function(){$(\'#ref-form\').slideDown()});</script>';
}
return $return;
}]
); ?>
现在我尝试将其转换为dropdownList,例如->
echo CHtml::dropDownList($add, 'type_contact',
$items, ['item' => function ($index, $label, $name, $checked, $value) {
$return = '<div style="max-height:178px!important;" class="radio col-xs-12 col-lg-6"><input type="radio" name="' . $name . '" value="' . $value . '" tabindex="3" id="' . $name . $index . '" ' . ($checked ? 'checked' : '') . '>';
$return .= '<label style="padding-top:0!important" for="' . $name . $index . '">' . $label . '</label></div>';
if ($checked && $index === 1) {
$return .= '<script>$(document).ready(function(){$(\'#ref-form\').slideDown()});</script>';
}
return $return;
}]
); ?>
并且具有htmlspecialchars()期望参数1为字符串,给定对象
C
前缀。2)您正在将表单字段与模型实例配对,因此应使用activeDropDownList()
方法而不是dropDownList()
。
3)在单选按钮选项中,您具有item
回调,该回调用于生成单选按钮的html代码。下拉列表没有类似的内容,因此您应该将其从选项中删除。您可以完全省略第四个参数,因为item回调是那里的唯一选项。
因此下拉列表的代码应如下所示:
echo Html::activeDropDownList($add, 'type_contact', $items);