Skip to content

[2.3][Form] Problem with setData and initialization of virtual form child #8253

Closed
@jeremyb

Description

@jeremyb

Hi @bschussek

I'm having an issue since I've updated my code to Symfony v2.3.1, I have an embed form defined as virtual and neither FormEvents::PRE_SET_DATA event nor setData method are called anymore.

I wrote a test to be more explicit on the problem I have: https://gist.github.com/jeremyb/5764427. I ran this test on the Symfony 2.2 and 2.3 branches and I think there's a regression on testVirtualAndEvents.

Test 2.2 2.3
testVirtual success success
testVirtualWithCountry fails fails
testVirtualAndEvents success fails

I'm trying to understand the differences made on Form component between 2.2 and 2.3 and I see some PR that can be related to this issue:

So I think my problem comes from the fact that setData isn't called for virtual forms and because auto_initialize prevents initialization of children (according to this the exception Automatic initialization is only supported on root forms.), so without initialization and data the FormEvents::PRE_SET_DATA event isn't called anymore. Is this correct?

I'm not sure whether it's a bug or an evolution of the Form component but is there a new way to do this kind of code and adapt the behavior of a virtual form from the data?

Let me know if you want me to commit my FormVirtualTest.php test somewhere, I can do a PR to your symfony fork if you want.

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