Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug #2369 [LiveComponent] (Dynamic Form) Do not clear missing values on submit #2397

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

momocode-de
Copy link

Q A
Bug fix? yes
New feature? no
Issues Fix #2369 / SymfonyCasts/dynamic-forms#26
License MIT

If you have a LiveComponent for a form with dependent fields which have been implemented with the dynamic-forms bundle, it can happen that the pre-defined value disappears for fields that are displayed later. This is due to the $clearMissing parameter of the Symfony\Component\Form::submit function. This parameter is true by default and therefore I now set it to “false” so that the values are not cleared.

I can't assess whether this would have unwanted side effects. Please check it out and if you think it fits, you can merge it.

@carsonbot carsonbot added Bug Bug Fix LiveComponent Status: Needs Review Needs to be reviewed labels Nov 20, 2024
@smnandre
Copy link
Member

Thank you for this PR @momocode-de!

I took time to look at it and one question arises: does this only change solves your DynamicFormBundle problem ? Or is this only a step ?

Right now i'm a bit hesitant here... if i(m not reading this badly, it would be a strong behaviour change:

When the second parameter $clearMissing is false, like with the "PATCH" method, the validation will only apply to the submitted fields. If you need to validate all the underlying data, add the required fields manually so that they are validated:

When submitting a form via a "PATCH" request, you may want to update only a few submitted fields. To achieve this, you may pass an optional second boolean argument to submit(). Passing false will remove any missing fields within the form object. Otherwise, the missing fields will be set to null.

https://symfony.com/doc/current/form/direct_submit.html

At least we would need some tests here, and a clear explanation of what would happen in the different scenario with some honest before/after.

Right now (and i'm very open to change my position)... i don't know... maybe you should first try to change this on your side? Because i'm not sure we should take this risk.. What do you think ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[LiveComponent] (Dynamic Form) Default values disappear for dynamically added fields
3 participants