我正在尝试以CheckBoxType
内的形式使用CollectionType
,但是原型只包含标签,根本没有复选框!
这真的很奇怪;我不明白,因为symfony文档here没有提及任何特殊的事情?
当我单击按钮添加新文件时,我只会看到标签
我想念什么?
收藏
->add('file', CollectionType::class, array(
'label' => false,
'entry_type' => FileType::class,
'error_bubbling' => false,
'entry_options' => [ 'required' => false, 'error_bubbling' => true, ],
'allow_add' => true,
'allow_delete' => true
))
FILETYPE
内的复选框
->add('main', CheckboxType::class,[
'label' => 'Make this one the main picture',
'required' => false,
]);
结果原型
data-prototype="<div id=\"new_item_group_pictures_itemFile___name__\"> <div class=\"form-item\"><div class=\"form-label\"></div><div class=\"custom-select\"><input type=\"file\" id=\"new_item_group_pictures_itemFile___name___file\" name=\"new_item[group_pictures][itemFile][__name__][file]\" class=\"form-file\" /></div></div> <div class=\"form-item\"><div class=\"form-label\"><label for=\"new_item_group_pictures_itemFile___name___description\">Description</label></div><input type=\"text\" id=\"new_item_group_pictures_itemFile___name___description\" name=\"new_item[group_pictures][itemFile][__name__][description]\" maxlength=\"255\" class=\"form-input form-text\" /></div> <div class=\"form-item\"><div class=\"form-label\"><label for=\"new_item_group_pictures_itemFile___name___main\">Make this one the main picture</label></div></div></div>"
实体属性
/**
* @var boolean
* @ORM\Column(type="boolean", nullable=true)
*/
private $main;
答案 0 :(得分:0)
集合类型的标签应为 true ,并且当您呈现集合类型的表单字段时,请使用 form_widget 而不是 form_row < / p>
答案 1 :(得分:0)
您必须对嵌入的表单集合进行迭代处理:
appendingPathComponent
这将呈现每个复选框,您可以在视图中对其进行操作
通常checkboxType应该可以正常工作,但是如果您想尝试其他解决方案,则可以将第二个表单设置为ChoiceType并添加扩展(以扩展复选框之类的选择)和多个true。
{% for t in form.file %}
{{ form_row(t) }}
{% endfor %}