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
6 Replies
LeandroFerreira
why aren't you using the submit action to do this?
TheRealTeeHill
TheRealTeeHillOP7d 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
would you like to keep the modal open?
TheRealTeeHill
TheRealTeeHillOP7d ago
yeah, it already does that, just need to clear the RichText input 🙂 I will take a look at modalSubmitAction 👍
LeandroFerreira
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();
})

Did you find this page helpful?