Clear RichText input after action

Hi All, I have a table action to view details, the action opens modal which has a RichText input to update a related model, this is working fine. When I submit the form I need to clear/empty the RichText input... any ideas, Google and LLMs have not got me to a solution yet 😦
Tables\Actions\Action::make('viewDetails')
->slideOver()
->form([
RichEditor::make('response')
->name('response')
->label('')
->required()
->afterStateUpdated(fn($state) => session()->put('response', $state))
->visible(fn($record) => !TicketService::isTicketClosed($record)),
])
->label('Details')
->icon('heroicon-o-eye')
->modalHeading(fn($record) => "#$record->id: $record->name ({$record->status->name})")
->modalContent(fn($record) => view('filament.actions.view-ticket-description', [
'owner' => $record->user->name,
'subject' => $record->name,
'description' => $record->description,
'time' => $record->formattedDate,
'responses' => $record->responses()->with(['user', 'agent'])->get(),
'copiedUsers' => $record->copiedUsers()->get(),
'agents' => $record->agents()->with('user')->get(),
]))
->modalSubmitAction(false)
->extraModalFooterActions([
Action::make('sendResponse')
->label('Send')
->color('primary')
->action(function ($record) {
if (!TicketService::validateResponse()) return;
TicketService::createTicketResponse($record);
TicketService::sendNotification("Ticket updated", "Your response to ticket #$record->id was sent.");
})
->visible(fn($record) => !TicketService::isTicketClosed($record)),
])
->closeModalByClickingAway(false),
Tables\Actions\Action::make('viewDetails')
->slideOver()
->form([
RichEditor::make('response')
->name('response')
->label('')
->required()
->afterStateUpdated(fn($state) => session()->put('response', $state))
->visible(fn($record) => !TicketService::isTicketClosed($record)),
])
->label('Details')
->icon('heroicon-o-eye')
->modalHeading(fn($record) => "#$record->id: $record->name ({$record->status->name})")
->modalContent(fn($record) => view('filament.actions.view-ticket-description', [
'owner' => $record->user->name,
'subject' => $record->name,
'description' => $record->description,
'time' => $record->formattedDate,
'responses' => $record->responses()->with(['user', 'agent'])->get(),
'copiedUsers' => $record->copiedUsers()->get(),
'agents' => $record->agents()->with('user')->get(),
]))
->modalSubmitAction(false)
->extraModalFooterActions([
Action::make('sendResponse')
->label('Send')
->color('primary')
->action(function ($record) {
if (!TicketService::validateResponse()) return;
TicketService::createTicketResponse($record);
TicketService::sendNotification("Ticket updated", "Your response to ticket #$record->id was sent.");
})
->visible(fn($record) => !TicketService::isTicketClosed($record)),
])
->closeModalByClickingAway(false),
Cheers, Tee
Solution:
I cannot believe how stupidly simple this was to resolve... after 8 hours of smashing my head against a wall yesterday... today I tried this and it worked! :therea54BLITZ: ```php RichEditor::make('response') ->name('response') ->label('')...
Jump to solution
7 Replies
LeandroFerreira
LeandroFerreira2mo ago
why aren't you using the submit action to do this?
TheRealTeeHill
TheRealTeeHillOP2mo ago
the code example I gave only shows the "Send" button but there are other buttons such as "Send and close", "Send and pending" so I thought custom action for each?
LeandroFerreira
LeandroFerreira2mo ago
would you like to keep the modal open?
TheRealTeeHill
TheRealTeeHillOP2mo ago
yeah, it already does that, just need to clear the RichText input 🙂 I will take a look at modalSubmitAction 👍
LeandroFerreira
LeandroFerreira2mo ago
take a look
Tables\Actions\Action::make('viewDetails')
->form([
RichEditor::make('response'),
])
->extraModalFooterActions(fn (Tables\Actions\Action $action): array => [
$action->makeModalSubmitAction('sendResponse'),
])
->action(function (array $data, Form $form, Tables\Actions\Action $action) {
$form->fill([
'response' => null,
]);
$action->halt();
})
Tables\Actions\Action::make('viewDetails')
->form([
RichEditor::make('response'),
])
->extraModalFooterActions(fn (Tables\Actions\Action $action): array => [
$action->makeModalSubmitAction('sendResponse'),
])
->action(function (array $data, Form $form, Tables\Actions\Action $action) {
$form->fill([
'response' => null,
]);
$action->halt();
})
Solution
TheRealTeeHill
TheRealTeeHill2mo ago
I cannot believe how stupidly simple this was to resolve... after 8 hours of smashing my head against a wall yesterday... today I tried this and it worked! :therea54BLITZ:
RichEditor::make('response')
->name('response')
->label('')
->required()
->afterStateUpdated(function ($state, $set) {
session()->put('response', $state);
$set('response', null); // THIS IS THE ANSWER!!!
})
->visible(fn($record) => !TicketService::isTicketClosed($record)),
RichEditor::make('response')
->name('response')
->label('')
->required()
->afterStateUpdated(function ($state, $set) {
session()->put('response', $state);
$set('response', null); // THIS IS THE ANSWER!!!
})
->visible(fn($record) => !TicketService::isTicketClosed($record)),

Did you find this page helpful?