Description
When using an ObjectChoiceList
with a value path given, and presetting the form data with some initial value, it only works if the object in the form data is the same instance as the corresponding object in the choice list.
I would expect the form data and the choices to be matched by their value (the value of the property at $valuePath
) instead. Indeed, this is what happens when the form is submitted: the request contains the value and Symfony uses it to retrieve the matching object from the choices.
Here is a fork of symfony-standard
that demonstrates this. The demo is located at /demo/objectchoicelist
.
https://github.com/oscherler/symfony-standard/tree/objectchoicelist
In the first 4 fields (Same instance …) I use an object from the choices to populate the form data, and the value is properly selected.
In the next 4 fields (Other instance …) I create a new object with the same properties (same value) as one of the objects in the choice list, and no value is selected.