-2

I have the following code, which I try to pre-select the 1st and 2nd option of the checkbox when rendered. However this doesn't work. Can anyone help me why?

  $builder->add('preferredContactTypes', 'entity', array('class' => 'AppMainBundle:ContactType', 'property' => 'type', 'multiple' => true, 'expanded' => true, 'mapped' => false, 'data' => array(1,2)))
adit
  • 32,574
  • 72
  • 229
  • 373

1 Answers1

1

the entity data field expects objects to be passed in not integers,

see this line:

'data'=>$em->getReference("TestGeneralBundle:Sucursal",3)

from this question:

Symfony2 Setting a default choice field selection

Community
  • 1
  • 1
Derick F
  • 2,749
  • 3
  • 20
  • 30