Access form data in modal action

I have the following action
Action::make('foo')
->form([
TextInput::make('fooBar')
])
->extraModalFooterActions([
Action::make('bar')
->action(function ($record, array $data) {
// $data is empty here
}),
])
->action(function ($record, array $data) {
// $data is available here because the form is submitted
}),
Action::make('foo')
->form([
TextInput::make('fooBar')
])
->extraModalFooterActions([
Action::make('bar')
->action(function ($record, array $data) {
// $data is empty here
}),
])
->action(function ($record, array $data) {
// $data is available here because the form is submitted
}),
Is there a way to get access to the value of the fooBar field inside Action::make('bar') ?
6 Replies
mark.cameron
mark.cameron2mo ago
It's ugly, and and probably not the way to go, but I found the form data here:
->extraModalFooterActions([
Action::make('bar')
->action(function ($record, Component $livewire) {
$data = $livewire->mountedTableActionsData[0];
}),
])
->extraModalFooterActions([
Action::make('bar')
->action(function ($record, Component $livewire) {
$data = $livewire->mountedTableActionsData[0];
}),
])
mountedTableActionsData is an array, so you might need to choose a different key than 0 depending on your setup.
Matthew
Matthew2mo ago
Why not just use $get ?
mark.cameron
mark.cameron2mo ago
@Matthew Doesn't work for me
Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization
Would need some way of accessing the parent form, as I don't believe it's available there in the nested action inside extraModalFooterActions
toeknee
toeknee2mo ago
Get wouldn't work to get values outside of the current component usually. You could try traversal but it's usually out of scope here just to the action.
Matthew
Matthew2mo ago
Ah... or use a form action instead ?
toeknee
toeknee2mo ago
You could do, but he wants the action in the footer with the other actions I assume. Even then the action is isolation I am fairly sure you can't traverse backwards.
Want results from more Discord servers?
Add your server