6

我将以下字段添加到我的表单中:

->add('interessi_profilo', 'entity', array( 
                'label' => 'Interessi (Tr)',
                'class' => 'MyProfiloBundle:TipoInteresse',
                'required'  => true,
                'multiple' => true,
                'expanded'  => true,
                'property' => 'tipo',
                'query_builder' => function(\My\ProfiloBundle\Entity\TipoInteresseRepository $er) {
                    return $er->createQueryBuilder('u')
                            ->orderBy('u.id', 'ASC');
                },

我希望仅在至少选中一个复选框时才发送表单,并且如果可能的话,有一个告诉用户的工具提示:at least one option must be selected

4

1 回答 1

11

尝试将Count约束放在保存集合的字段上:

use Symfony\Component\Validator\Constraints\Count;

class Entity 
{
    /**
     * @Count(min = 1, minMessage = "At least one item must be selected")
     */
    private $collection;

    // ...
}
于 2013-03-01T12:16:48.810 回答