Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] ObjectChoiceList should select initial field value based on the value property. #8825

Copy link
Copy link
Closed
@oscherler

Description

@oscherler
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.