具有默认选定值的多个下拉列表

我正在添加多个下拉列表,但我希望默认选择一些值。

form->addField('DropDown', 'fieldname','Field Caption')->setAttr('multiple')->setModel('SomeModel');

因此,当用户打开此表单时,将选择id为1,5和6的值。 我检查了互联网,但没有找到任何这方面的例子..

还检查了atk4 \ lib \ Form \ Field \ DropDown.php,但无法找到解决方案:(

我知道表单的通常用法是这样的:

$form->addField('line','name')->set('John');

但是id在这里不起作用?

提前致谢!

解:

if($campaign->get('labels')){
$jsfunction = 'var values="'.$campaign->get('labels').'";$.each(values.split(","), function(i,e){$("#nottyfly_createcampaign_form_labels option[value=\'" + e + "\']").prop("selected", true);})';
  $this->js(true,$jsfunction);
}
author: peter
采纳答案:

这不是在ATK4 Form_Field_DropDown类中实现的,但我猜你在这种情况下可以用jQuery(JavaScript)做一些事情 - 在带有JS的文档/字段onLoad事件上的select()值。

author: peter

参考更多解答: Multiple dropdown with default selected values ,转载请保留出处具有默认选定值的多个下拉列表及作者信息

Statement: We respect knowledge and authors. Since the content comes from the Internet and is intended for scientific research, any reprinters should retain the author's signature and origin. If you are the author of the content and feel in dispute, please contact email: 1076545519@qq.com. We will find out the situation and deal with it in time. We sincerely thank the author for his hard work.


更多:atk4