How to pass form data when using replaceMountedAction()

Hi, I've created a header action with a form that replaces itself with another action. I need help passing the form data from the first action to the second. I've reviewed the docs and read up on passing $data and $arguments, but I can't get it to work. The goal is for the first action to appear as a modal where the user can enter search terms. When entered, those keywords are passed as part of $data to the next action that is mounted so I can show the user their keywords. Can anyone help me figure this out. I've provided the relevant code here.
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Infolists\Components\TextEntry;
use Filament\Resources\Pages\ViewRecord;

class Discord extends ViewRecord
{
// Other Filament stuff

public function getHeaderActions(): array
{
return [
Action::make('search')
->action(function (array $data) {
$this->replaceMountedAction('results', $data);
})
->form(
[
TextInput::make('keywords'),
]
)
->modal()
->slideOver(),
];
}


public function resultsAction(): Action
{
return Action::make('results-picker')
->action(function (array $data) {
// Do API things
})
->infolist(
[
TextEntry::make('keyword')
->label('These are the keywords you picked')
->getStateUsing(function ($data) {
return $data['keywords'];
}),
]
)
->modal()
->slideOver();
}
}
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Infolists\Components\TextEntry;
use Filament\Resources\Pages\ViewRecord;

class Discord extends ViewRecord
{
// Other Filament stuff

public function getHeaderActions(): array
{
return [
Action::make('search')
->action(function (array $data) {
$this->replaceMountedAction('results', $data);
})
->form(
[
TextInput::make('keywords'),
]
)
->modal()
->slideOver(),
];
}


public function resultsAction(): Action
{
return Action::make('results-picker')
->action(function (array $data) {
// Do API things
})
->infolist(
[
TextEntry::make('keyword')
->label('These are the keywords you picked')
->getStateUsing(function ($data) {
return $data['keywords'];
}),
]
)
->modal()
->slideOver();
}
}
1 Reply
BuddhaNature
BuddhaNature3mo ago
After some trial and error, this gave me the result, I am looking for, but it doens't look like an ideal solution.
TextEntry::make('keyword')
->state(function () {
return $this->mountedActionsArguments[0]['keywords'];
})
TextEntry::make('keyword')
->state(function () {
return $this->mountedActionsArguments[0]['keywords'];
})
Want results from more Discord servers?
Add your server