我有Namespace\Entity\MainEntity
的表单,其中包含如下子表单:
->add('property1', TextType::class, array(
'required' => false,
'label' => 'This is the form label',
'data_class' => 'Namespace\Entity\SubFormEntity',
'attr' => array(
'class' => 'form-control'
)
))
->add('property2', SubFormType::class)
SubFormType
本身有一个文本字段,如下所示:
->add('subproperty1', TextType::class, array(
'label' => false,
'attr' => array(
'class' => 'form-control'
)
))
如果我提交表单,property1
会得到正确验证,但property2
的验证不会被触发,即使subform_field
的值不正确,也会提交表单。
我试过......
Namespace\Entity\SubFormEntity:
properties:
property2:
- Type:
type: numeric
......和......
Namespace\Entity\MainEntity:
properties:
property2.subproperty1:
- Type:
type: numeric
如何启用subproperty1
字段的验证?
答案 0 :(得分:2)
启用(master $=) $ git merge dev --strategy=theirs
(documentation),让您的子表单错误显示在父表单中。
对PrintWriter output;
output=createWriter(*someDirectory*); //such as data/outputText.txt
String [] previousText = loadStrings (*someDirectory*) //same as above
String newText= "This is a new line that won't destroy entire text file";
for (int i=0; i<previousText.length; i++) {
output.println(previousText[i]);
}
output.println(newText);
output.flush();
output.close();
使用以下验证映射:
error_bubbling
将Valid
约束添加到SubFormEntity
的验证映射中:
Namespace\Entity\SubFormEntity:
properties:
subproperty1:
- Type:
type: numeric
将MainEntity
选项添加到 Namespace\Entity\MainEntity:
properties:
property2:
- Valid
:
error_bubbling
...或在您的SubFormType
中加入public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
// ...
'error_bubbling' => true
));
}
时动态添加选项:
SubFormType