At least one Symfony2 flag selected

I add the following field to my form:

->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'); }, 

I would like the form to be submitted only if at least one checkbox is selected and, if possible, has a tooltip that tells the user: at least one option must be selected

+4
source share
1 answer

Try placing the Count constraint in the field in which the collection is located:

 use Symfony\Component\Validator\Constraints\Count; class Entity { /** * @Count(min = 1, minMessage = "At least one item must be selected") */ private $collection; // ... } 
+7
source

All Articles