Skip to content

[LiveComponent] ComponentWithFormTrait::extractValues does not properly flattens data #864

Closed
@norkunas

Description

@norkunas

Comment from the trait:

This is used to pass the initial values into the live component's
frontend, and it's meant to equal the raw POST data that would
be sent if the form were submitted without modification.

But "would be sent if the form were submitted without modification" is not correct. When you render an empty form and select entity in autocomplete the value is an string ID which is converted to an entity in backend and not the entity itself. So when using form with DTO and ux autocomplete when property in DTO is predefined - aka entity is set on it the value is not flattened to the ID.

Now after upgrade to the latest dev in tests we started to get:

Uncaught PHP Exception Twig\Error\RuntimeError: "Error rendering "InvoiceCreateForm" component: The LiveProp "formValues" on component "InvoiceCreateFormComponent" is an array, but it contains one or more keys that are not scalars: formValues.customer: Proxies\__CG__\App\Entity\User" at /var/www/html/templates/Invoice/create.html.twig

Also based on the autocomplete structure it should be flattened to formValues.customer[autocomplete] but I see only formValues.customer

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