RichEditor: Dynamic mergeTags based on other fields value

I am building simple email templating, and want mergeTags to be dynamic based on other fields value. When I select entities field, the mergeTags should have now have value based on the entity selected. but mergeTags, still the same with initial value even after form update.
return $schema
->components([
Section::make('Template Details')
->components([
Group::make([
TextInput::make('name')
->required(),
TextInput::make('subject')
->required(),
TextInput::make('description'),
]),
ToggleButtons::make('entities')
->live()
->multiple()
->options(EntityEnum::class),
])
->compact()
->columns(2)
->columnSpanFull(),
RichEditor::make('body')
->toolbarButtons(['mergeTags'])
->mergeTags(function (Get $get): array {
$entities = $get('entities') ?? [];
$variables = [];
foreach ($entities as $entity) {
if ($entity->value === EntityEnum::Invoice->value) {
$variables = [
'invoice.number' => 'Invoice Number',
'invoice.date' => 'Invoice Date',
];
}
}

return $variables;
})
->required()
->columnSpanFull(),
]);
return $schema
->components([
Section::make('Template Details')
->components([
Group::make([
TextInput::make('name')
->required(),
TextInput::make('subject')
->required(),
TextInput::make('description'),
]),
ToggleButtons::make('entities')
->live()
->multiple()
->options(EntityEnum::class),
])
->compact()
->columns(2)
->columnSpanFull(),
RichEditor::make('body')
->toolbarButtons(['mergeTags'])
->mergeTags(function (Get $get): array {
$entities = $get('entities') ?? [];
$variables = [];
foreach ($entities as $entity) {
if ($entity->value === EntityEnum::Invoice->value) {
$variables = [
'invoice.number' => 'Invoice Number',
'invoice.date' => 'Invoice Date',
];
}
}

return $variables;
})
->required()
->columnSpanFull(),
]);
5 Replies
Dennis Koch
Dennis Kochβ€’2mo ago
I don't think the editor will rerender once initialised. Maybe you can try a partial rerender, but I don't think that it will work: ->partiallaRenderComponentsAfterStateUpdated(['body'])
Gerald Afable
Gerald AfableOPβ€’2mo ago
Hi @Dennis Koch , thanks for the reply, but sadly it does not work. Is there a way to force editor to re render when change happen to the other field? Or it is really design in the way
Dennis Koch
Dennis Kochβ€’2mo ago
I don't think so. The editor is wire:ignored so any changes in Livewire won't affect it, because it would break its state. And the merge tags are rendered via Blade, so you can't control it via JS. Your only option is a full page reload.
Gerald Afable
Gerald AfableOPβ€’2mo ago
Thanks for this input πŸ™‡
elmudometal
elmudometalβ€’4w ago
and if you disable and enable it after changing the values?

Did you find this page helpful?