Repository navigation
[Form] Don't re-add deleted collection entries on submit - #64536
nicolas-grekas merged 1 commit into
Conversation
|
Thank you @eyupcanakman. |
|
@nicolas-grekas I don't suppose this justifies a 8.1.1 release? I'm about to revert about 30 sites to 8.0 as this is causing errors across each site. |
|
The issue still persists. Have tried today with Symfony 8.1.1 and have a form field in collectionType as constraint notBlank. When removed the row and click on submit button it gave the message that the form field is required. This issue araise when contraints are added to a field in a formType. If the field is defined as "requried => true", on submission it remove the row. |
Please open a new issue and provide an example application that allows to reproduce your issue. Comments on merged PRs are likely to get lost. |
Since 8.1 the request handlers call
MissingDataHandler::handle()before$form->submit(). For aCollectionTypewithallow_delete, the handler walks the children that still exist at that point, including an entry the user removed, and synthesisesfalse_valuesdefaults for itsfalse_values-aware children (CheckboxType, expanded multipleChoiceType, ...). That re-adds the entry to the submitted data, soResizeFormListener::preSubmit()(which drops entries whose key is absent viaisset()) keeps it instead of removing it.The fix skips a child entirely absent from the submitted data when the form has
allow_delete, mirroring theResizeFormListenercondition, so a removed entry stays removed. Afalse_values-aware child inside a kept entry is still synthesised.The regression test in
AbstractRequestHandlerTestCasecovers bothNativeRequestHandlerandHttpFoundationRequestHandleracross POST/PUT/DELETE/GET; reverting the fix makes all 8 variants fail, applying it makes them pass.