Description
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:
Then I checked in the form SUBMIT event, and the id is lost at this point:
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.