Skip to content

[symfony/ux-live-component] data-model property name mismatch with ComponentWithFormTrait #2886

Open
@elyukai

Description

@elyukai

Description

I’m trying to fiddle around with embedded components in combination with ComponentWithFormTrait and I cannot get it running.

If I use a form named task, the formValues property will also be having that name, so in order to add the data-model attribute, I have to replace the form name in the full name of the field.

{%- block textarea_widget -%}
    <twig:MarkdownTextarea
        name="{{ full_name }}"
        data-model="{{ full_name|preg_replace('/^.+?\\[/', 'formValues[') }}"
    />
{%- endblock textarea_widget -%}

Side note: I added the preg_replace filter myself and it just bridges to the preg_replace function of PHP.

This way, the linking itself works and I’m not getting an An exception has been thrown during the rendering of a template ("Can't get a way to read the property "task" in class "App\Twig\Components\Tasks\TaskForm".") error.

However, once I try to actually update the value, I’m getting JavaScript errors from the parseDeepData function. It is happening because the first part of the parts is now formValues, while the property on the component is called task. (TypeError: undefined is not an object (evaluating 'currentLevelData[parts[i]]'))

How can use data-model for a reusable theme component that also works in a ComponentWithFormTrait component? This seems like a bug to me, but maybe I oversaw something.

Thank you in advance!

Used versions

  • symfony/ux-live-component: 2.26.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions