【发布时间】:2019-09-26 14:28:18
【问题描述】:
我正在尝试一种上传多个文件的方法。
我在 buildForm 方法中添加了一个约束以允许某些类型的文件。但是,当文件类型不好时,{{ form_errors(form.documents) }}不会显示错误信息。
这是我的表格:
票务类型:
->add('documents', CollectionType::class, array(
'entry_type' => TicketDocumentType::class,
'prototype' => true,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'required' => false,
'label' => false,
))
TicketDocumentType :
->add('file', FileType::class, array(
'label' => false,
'required' => true,
'constraints' => [
new File([
'maxSize' => '400k',
'mimeTypes' => [
"image/png",
"image/jpeg",
"image/jpg",
"image/gif",
"image/x-citrix-jpeg",
"image/x-citrix-png",
"image/x-png",
"application/pdf",
"application/x-pdf",
"application/vnd.ms-excel",
"application/msword",
"text/plain",
"application/zip"
],
'mimeTypesMessage' => 'Les formats autorisés sont PDF, TXT, DOC, XLS, JPG, PNG, GIF, ZIP',
])
]
));
经过一番研究,我发现我可以将'error_bubbling' => true 与{{ form_errors(form) }} 一起使用。
但是,我希望只有 form.documents 错误。这可能吗?
【问题讨论】:
标签: symfony constraints symfony4