Forms 表单集合冒泡错误
您好,我的表单中的文本字段集合有问题。当其中一个字段中出现错误时,这些错误会冒泡到父窗体中,这样它们就不会被指定给字段,而是被指定给父窗体本身。它是下面代码段中的“点”集合。我试图将error_bubbling设置为false,但没有效果Forms 表单集合冒泡错误,forms,symfony,collections,Forms,Symfony,Collections,您好,我的表单中的文本字段集合有问题。当其中一个字段中出现错误时,这些错误会冒泡到父窗体中,这样它们就不会被指定给字段,而是被指定给父窗体本身。它是下面代码段中的“点”集合。我试图将error_bubbling设置为false,但没有效果 <?php namespace JamaLvova\AdminBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Componen
<?php
namespace JamaLvova\AdminBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use JamaLvova\AdminBundle\Form\Type\ExercisePointsFormType;
class StartContestFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('startYear', 'hidden')
/*
some other form elements
*/
->add('points', 'collection', array(
'type' => 'text',
'allow_add' => true,
'label' => 'Body za jednotlivé úlohy:',
'error_bubbling' => false,
'options' => array(
'error_bubbling' => false,
'attr' => array("maxlength" => "4", "size" => "4")
)
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'JamaLvova\AdminBundle\Form\StartContestForm',
));
}
public function getName()
{
return 'startContestForm';
}
}
在细枝模板中,当我迭代form.points时,没有字段有错误,但form.points有错误。有人知道问题出在哪里吗?还是我遗漏了什么?非常感谢:-)(Symfony v.2.1.4)
EDIT:如果我使用表单集合('type'=>newpointsformtype()),而不是使用'type'=>'text',它似乎可以按预期工作。这是否意味着我总是需要使用表单集合才能将错误分配给特定字段?您可能需要添加
cascade\u validation'=>true
$builder->add('startYear', 'hidden')
/*
some other form elements
*/
->add('points', 'collection', array(
'type' => 'text',
'allow_add' => true,
'label' => 'Body za jednotlivé úlohy:',
'error_bubbling' => false,
'cascade_validation' => true,
'attr' => array("maxlength" => "4", "size" => "4")
));
}
小心,因为已从Sf3中删除了
cascade\u validation
属性:
Symfony 2.8和中已不推荐使用cascade_验证选项
将在3.0中删除。相反,请在应用程序中使用有效约束
模型到级联验证。请注意以下事实:
子表单将不考虑验证组选项
$builder->add('startYear', 'hidden')
/*
some other form elements
*/
->add('points', 'collection', array(
'type' => 'text',
'allow_add' => true,
'label' => 'Body za jednotlivé úlohy:',
'error_bubbling' => false,
'cascade_validation' => true,
'attr' => array("maxlength" => "4", "size" => "4")
));
}