Skip to content

[Live Component][Dependent Form Fields] reference lost during submit cause unwanted insertion instead of update #2176

Closed
@fGuix

Description

@fGuix

Hello,
I'm using the dependent form fields in a project and I noticed I guess a bug.

In my form type, I have this code:

$builder
...
  ->addDependent('shippingAddress', 'shippingSameAsBillingAddress', function (DependentField $field, ?bool $billingSameAsShippingAddress) use ($options) {
      if (false === $billingSameAsShippingAddress) {
          $field->add(UserAddressType::class, [
              'mapped' => false,
              ...
          ]
          );
      }
  });

Notice this is an unmapped field.
During the POST_SET_DATA event, I populate the field with setData() and an entity of class UserAddress. Everything works well.

The problem comes with the submit operation. Doctrine tries to insert a new entity instead of updating the existing.
A. I checked the state of my form data, and in the form PRE_SUBMIT event, the id is still here:
image
Then I checked in the form SUBMIT event, and the id is lost at this point:
image
Thus, it tries to create a new userAdress.

B. I tried replacing the dependent field with a classic one, and it works as expected (updating the entity instead of trying to create a new one).

C. might be related to this issue as I didn't get the problem when creating a new one. Only when editing an existing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions