Skip to content

[LiveComponent] <textarea> not updated #1078

@JorickPepin

Description

@JorickPepin

Hello, I'm experiencing a strange behavior when trying to display my dynamic content in a <textarea>. When my function returns an empty string at the start, I get the impression that the content isn't injected into the DOM if I put it in a <textarea>, but that it works if it's in a <div>.

I tried to make a simple reproducer where we retrieve the content of a <textarea> to display it in another one by applying some processing. The content doesn't seem to appear in the DOM if the first iteration of this processing returns an empty string. Don't hesitate if you need more details.

The LiveComponent:

#[AsLiveComponent]
class TestComponent extends AbstractController
{
    use ComponentWithFormTrait;
    use DefaultActionTrait;

    public array $initialFormData = [
        'editor' => '',
    ];

    public function getUpdatedText(): string
    {
        $data = $this->getForm()->getData();

        return $data['editor']; // does not appear in the DOM
        // return $data['editor'] . ' updated'; // appears in the DOM
    }

    protected function instantiateForm(): FormInterface
    {
        return $this->createForm(
            TestType::class, $this->initialFormData
        );
    }
}

The FormType:

class TestType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('editor', TextareaType::class, [
                'label' => false,
                'trim' => false,
            ]);
        ;
    }
}

The template:

<div {{ attributes }}>
    {{ form_start(form) }}
        {{ form_row(form.editor) }}
        <textarea>{{ this.updatedText }}</textarea>
        <div>{{ this.updatedText }}</div>
    {{ form_end(form) }}
</div>

Screens:
image image

image image

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugBug Fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions