I am adding 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 for the form to be sent only if at least one checkbox is selected and, if possible, have a tooltip that tells the user: at least one option must be selected
Try putting the Count
constraint on the field holding the collection:
use Symfony\Component\Validator\Constraints\Count;
class Entity
{
/**
* @Count(min = 1, minMessage = "At least one item must be selected")
*/
private $collection;
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With