So I was using symfony for a while but there is problem that, each time I face it, I get very angry, seriously :).
Let's assume I have an entity Client
with OneToMany
relation with entity Address
, and let's say I have a form with two selects: Clients and Addresses, so I select a client and load it's addresses in the select below dynamically using ajax, as described in the picture below:
After sending the form with selected client and address symfony gives me this error about the addresses select:
This value is not valid
This is my builder that gave me this error:
$builder
->add('client', EntityType::class, array(
'class' => Client::class,
))
->add('addresses', EntityType::class, array(
'class' => Address::class,
'choices' => array(), //---To force symfony to not launch a query to get all addresses
))
When I remove the line 'choices' => array()
the form works fine and send the data correctly.
I really need to solve this issue because I need something like that a lot in my application that I'm now working on it.