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

[LiveComponent] (Dynamic Form) Default values disappear for dynamically added fields #2369

Open
momocode-de opened this issue Nov 13, 2024 · 3 comments · May be fixed by #2397
Open

[LiveComponent] (Dynamic Form) Default values disappear for dynamically added fields #2369

momocode-de opened this issue Nov 13, 2024 · 3 comments · May be fixed by #2397
Labels

Comments

@momocode-de
Copy link

I have a LiveComponent for a form. This form has dependent fields which have been implemented with the dynamic-forms bundle. I have a situation where I have select fields that are only added when certain other fields have been filled in. These select fields should have a preselected value. To do this, I set the value in the corresponding fields in the object for the initial form values. The problem is that these values disappear when the fields are added and therefore no value is preselected in the fields. There is already an issue for this in the dynamic-forms bundle. I have now debugged it and found out what the problem is. This is due to the $clearMissing parameter of the Symfony\Component\Form::submit function. This parameter is true by default. The function is called here without the 2nd parameter. If I set the 2nd parameter to false, the problem is solved. I could create a PR for it now, but unfortunately I can't assess whether this would have unwanted side effects. Can anyone say? Is it ok to set the $clearMissing parameter to false in the ComponentWithFormTrait on submit?

@smnandre
Copy link
Member

Hi @momocode-de, thank you for this very detailed report 🙇

I'd say, let's open this PR and we will iterate on it and see what effects it could have :)

momocode-de added a commit to momocode-de/symfony-ux that referenced this issue Nov 20, 2024
@Huluti
Copy link

Huluti commented Dec 13, 2024

Capture vidéo du 2024-12-13 10-28-17

For me it's an important problem in Symfony UX because for a simple use-case like this with SymfonyCasts/dynamic-forms, you can't select a default value for the dependant field. Here for the month selector I would like to have the current month selected (December) instead of the first option (January).

@smnandre
Copy link
Member

@Huluti There is an open PR, if you can have a look and discuss alternatives

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