Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Have a way to Force the update of form data after submit when handling dynamic forms #57942

Open
@khalid-s

Description

@khalid-s

Description

Currently when a form is submitted, we can bring in some changes like adding/removing a field but we cannot change the data of other fields.
While this makes sense and we should definitely keep, since when using the form events, generally when handling dynamic fields, we post the form with errors and symfony needs to be able to redisplay the form's previous state.

But sometimes we do need to be able to change the form's data when there is an error in the form. This should be used with caution.

There has been a few questions on this on StackOverflow which remained unanswered:

https://stackoverflow.com/questions/69617171/symfony-form-event-change-choice-field-options-based-on-other-choice-field/78845395#78845395

https://stackoverflow.com/questions/78836877/symfony-post-submit-update-data-of-underlying-object/78845393#78845393

Example

For example, let's say i have 2 fields which are ofEntityType, the second on beingmultiple => true like this:

->add('series', EntityType::class, [    'label' => 'Collection',    'class' => Series::class,    'choice_label' => 'name',])->add('forbiddenCountries', EntityType::class, [    'class' => Country::class,    'multiple' => true])

By default, no values are selected in theseries, I need to preset some values in theforbiddenCountries, I would add an EventListener for the PRESET_DATA on the form. For this part no problem.

By in my app, if theseries field is null, theforbiddenCountries should default to some values else, it should have other values preset.

So to achieve this, I would need to listen to the POST_SUBMIT event of theseries field, then update the data of theforbiddenCountries. And this last part is not possible with symfony.

-- hacks

If i want to handle this in symfony, I would need to use unmapped fields and work with denormalized data which I would then have to re-normalize.

The other solution, which is the one i opted for, use javascript along with an API. On change on theseries field, I would take the value and call my API to get a fresh list of data to preset in myforbiddenCountries and update it using js.

Both hack comes with huge drawbacks.

This is why it would be great to have a way to"force" (meaning the dev expressly understand the consequences of this specific action) the update of the underlying data

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp