有任何方法可以知道父表单是否有效。这是代码。它总是抛出:“您不能在未绑定的表单上调用 isValid()。”。谢谢!!
class FoorType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('field_1') // Required
->add('field_2') // Required
->add('field_3') // Required
->add('bar', 'my_custom_form_type') // Not required
}
}
class MyCustomFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventListener(FormEvents::POST_BIND, function(DataEvent $event) {
$form = $event->getForm();
$data = $event->getData();
if ($form->getParent()->isValid()) {
// Do smething...
}
});
}
public function getParent()
{
return 'text';
}
public function getName()
{
return 'my_custom_form_type';
}
}