我使用本教程嵌入了一组表单。如何添加验证以确保提交的表单至少包含一个表单?
Symfony 现在有一个Count约束,可以与集合类型一起使用来设置最小项目数:
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
$formBuilder->add('example', CollectionType::class, [
// other options...
'constraints' => [
new Assert\Count([
'min' => 1,
'minMessage' => 'Must have at least one value',
// also has max and maxMessage just like the Length constraint
]),
],
]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2682 次 |
| 最近记录: |