-
-
Notifications
You must be signed in to change notification settings - Fork 383
Closed
Labels
BugBug FixBug Fix
Description
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>
Metadata
Metadata
Assignees
Labels
BugBug FixBug Fix