© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•4mo ago•
6 replies
Gerald Afable

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(),
            ]);
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

MergeTags in Richeditor
FilamentFFilament / ❓┊help
6mo ago
Form field value based on 2 other fields
FilamentFFilament / ❓┊help
13mo ago
Update RichEditor based on other field
FilamentFFilament / ❓┊help
2y ago
Dynamic form fields based on dependant fields
FilamentFFilament / ❓┊help
3y ago