Hi, I have problem with choice using multiple choice, if I use 'multiple'=>false it works but it's useless for collection.
Document:
/**
* @var ArrayCollection<Tag> $tag
* @ODM\ReferenceMany(targetDocument="Tag")
*/
protected $tags;
public function __construct()
{
$this->tags = new ArrayCollection();
}
Admin (FormFields):
$tagQuery = $this->getModelManager()->createQuery('FitpointBundle:Tag')->execute();
...
->add(
'tags',
'choice',
[
'multiple' => true,
'required' => false,
'choices' => $tagQuery,
'choice_label' => function ($tag, $key, $index) {
/** @var Tag $tag */
return $tag->getTitle();
},
]
)
...
I try to use sonata_type_model but that ends with Notice: Undefined index: choice_list which is related to https://github.com/sonata-project/SonataAdminBundle/issues/3529
I also tried autocomplete with:
->add('tags', 'sonata_type_model_autocomplete', [
'multiple' => true,
'property'=>'title',
'required' => false
])
error:
Catchable Fatal Error: Argument 1 passed to Sonata\AdminBundle\Form\DataTransformer\ModelToIdPropertyTransformer::__construct() must implement interface Sonata\AdminBundle\Model\ModelManagerInterface, null given, called in /<path>/vendor/sonata-project/admin-bundle/Form/Type/ModelAutocompleteType.php on line 37 and defined
This is solved in current 3.x branch
Most helpful comment
This is solved in current 3.x branch