问题
我有一个Form
和一个FieldSet
。我想验证FieldSet
不是空的。另外,我想验证FieldSet
.
到目前为止,我所尝试的都是验证一个或另一个,但不能同时验证两者。如果elements
存在于表单的输入过滤器规范中,则它验证它elements
不是空的,但不验证bar
和的baz
字段FieldSet
。当然,反过来。任何有关如何解决此问题的线索将不胜感激。
表格
class FooForm extends Form implements InputFilterProviderInterface
{
public function init()
{
$this->add([
'name' => 'elements',
'type' => Collection::class,
'required' => true,
'options' => [
'target_element' => [
'type' => SomeElementFieldSet::class
]
]
]);
}
public function getInputFilterSpecification()
{
return [
[
'name' => 'elements',
'required' => true,
'validators' => [
['name' => 'NotEmpty']
]
]
];
}
}
字段集
class SomeElementFieldSet extends Fieldset implements InputFilterProviderInterface
{
public function init()
{
$this->add(['name' => 'bar']);
$this->add(['name' => 'baz']);
}
public function getInputFilterSpecification()
{
return [
[
'name' => 'bar',
'required' => true,
'validators' => [
['name' => 'NotEmpty']
]
],
[
'name' => 'baz',
'required' => true,
'validators' => [
['name' => 'NotEmpty']
]
]
];
}
}
编辑:添加了完整的验证规范。