Is it possible to generate select list where options will be retrieved from database and there will be option (with JS) to multiply field ?
I've copied my code, maybe it will help.
$builder->add('device', 'collection', array(
'type' => 'entity',
'label' => ' ',
'options' => array(
'class' => 'TrashTrashAdminBundle:DeviceType',
'property' => 'name',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('d')
->where('d.isLighting = 1');
},
),
'attr' => array('class' => 'form-control device')
))
You are trying to work with collection
field type in way as you would work with entity
field type. You should change collection
for entity
:
$builder->add('device', 'entity', array(
'options' => array(
'class' => 'TrashTrashAdminBundle:DeviceType',
'property' => 'name',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('d')
->where('d.isLighting = 1');
},
),
'attr' => array(
'class' => 'form-control device'
))
);
After the select box is generated, you can make changes, which you mentioned, at your will.