Skip to content

[ComponentWithFormTrait][formValues] Before and after AJAX #2646

Open
@GrinWay

Description

@GrinWay

The following is not documented and may be confusing:

  1. Before the AJAX request exactly how POST PAYLOAD DATA (by the data-live-props-value) are built to be submitted
  2. After the AJAX what data-live-props-value html attribute will finally be.

I ask this because I came accross with the following:

  1. I have a live form with ChoiceType (datetimes)
  2. AJAX is called (because I pushed the button submit)
  3. My datetimes (ChoiceType) were updated during PRE_SUBMIT event, because of they are dynamic
  4. All the possible choices not contain PAYLOAD[datetime] because it's already doesn't exist among choices, as a result normalized version of the data is null because of the default ChoiceType data transformer
  5. AJAX is finished and I have the old datetime in the data-live-props-value attribute, because it was not changed via frontend but because of the internal logic choices changed (in the PRE_SUBMIT event) I have null model data
  6. FINALLY: I have null model datetime data, but I expected I was the first element of the choice

To solve this I needed to empty formValues before form creation to make data-live-url-value contain first choice element instead of the old currently non-existent element in the choice

But currently it's not clear

In case I did NOT empty formValues before the form creation I would constantly get empty normalized data in my MODEL/ENTITY because data-live-props-value html attribute would constantly contain old non-existent choice unless it was selected from frontend (in this case it would be updated as normal)

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions