Access form with extra modal footer

I'd like to access the form data with $get in an extra footer action
Solution:
https://filamentphp.com/docs/3.x/forms/actions I've found this, I'm going to move the footer actions into the form...
Jump to solution
31 Replies
Jordy
JordyOP2w ago
Action::make()
->modal()
->form([...])
->extraModalFooterActions([
Action::make('start')
->hidden(fn(Get $get) => $get('form_input') == null),
])
Action::make()
->modal()
->form([...])
->extraModalFooterActions([
Action::make('start')
->hidden(fn(Get $get) => $get('form_input') == null),
])
this throws "Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization".. which somewhat makes sense since I guess the extra footer action is not inside the actual form is there another way I can get live data from the form to toggle my extra action's visibilty?
LeandroFerreira
maybe injecting $livewire and using $livewire->mountedActionsData 🤔
Jordy
JordyOP2w ago
This is an empty array and doesnt seem to get filled I guess hidden() is ran before the action is mounted?
LeandroFerreira
I think so
Jordy
JordyOP2w ago
I'll just have them save and revisit the modal then I guess
LeandroFerreira
I don't know what you are trying to do, but I think if form_input is live, this will work when you change the field value..
Jordy
JordyOP2w ago
the input is live, it doesnt work though,
->hidden(function ($livewire) {
if (!empty($livewire->mountedActionsData)) {
dd($livewire->mountedActionsData);
}
}),
->hidden(function ($livewire) {
if (!empty($livewire->mountedActionsData)) {
dd($livewire->mountedActionsData);
}
}),
this never dumps, I guess because hidden is not ran again to re check visbility since the action is not inside the form 🤔 live just tells the form to reload.. so I'm assuming the action isnt inside of the form Let me clarify then, I have some inputs inside of a modal (table action) I have some extraModalFooterActions(), that I want to be visible depending on the state of some of the inputs in the modal I can get around this by having the user save first and then just accessing $record.. but it requires them to click 2 times.. which is a bit annoying
ModestasV
ModestasV2w ago
It should be reachable via $livewire->form
Jordy
JordyOP2w ago
how do I access input values from here?
ModestasV
ModestasV2w ago
Huh, I might have mixed a place. Buut, it's possible to get to the action via:
$livewire->getTable()->getActions()
$livewire->getTable()->getActions()
In my case, this gets to action form data, but it is not really reactive:
Action::make('modal_stuff')
->modal()
->form([
Forms\Components\TextInput::make('test'),
Forms\Components\Checkbox::make('form_input')
])
->extraModalFooterActions([
Action::make('start')
->hidden(function ($livewire) {
dd($livewire->getTable()->getActions()[1]->getFormData());
}),
])
Action::make('modal_stuff')
->modal()
->form([
Forms\Components\TextInput::make('test'),
Forms\Components\Checkbox::make('form_input')
])
->extraModalFooterActions([
Action::make('start')
->hidden(function ($livewire) {
dd($livewire->getTable()->getActions()[1]->getFormData());
}),
])
But this might be a direction 😅
Jordy
JordyOP2w ago
I'm unsure if that would be reactive to the live input though I'd assume not
ModestasV
ModestasV2w ago
Okay, it seems that the ->hidden() runs once for each row and doesn't get called again unless you have it somewhere else, not in a table row?
Solution
Jordy
Jordy2w ago
https://filamentphp.com/docs/3.x/forms/actions I've found this, I'm going to move the footer actions into the form
Jordy
JordyOP2w ago
which will resolve the issue since it would be reloaded by the ->live() method Thanks for the effort :)
ModestasV
ModestasV2w ago
No worries! Sad that couldn't help, but was interesting brain itch 😄
Jordy
JordyOP2w ago
well it somewhat makes sense.. I just assumed the buttons/actions are inside the form which they apparently are not
ModestasV
ModestasV2w ago
wait, but how does the submit button then get handled? maybe reverse-engineering that? Or actually.. what if you trigger an event? Wouldn't that work...?
Jordy
JordyOP2w ago
livewire emit I suppose?
The field that you depend on (the status in this case) needs to be set to live(), which tells the form to reload the schema each time it gets changed.
and I guess ->live() just emits specifically the the components inside the schema array but I'm just guessing here
ModestasV
ModestasV2w ago
Might be, but you could also emit something else via: ->afterStateUpdated($callback) In that case, you could try to listen for that event on action but that's a wild guess 😄
Jordy
JordyOP2w ago
time to go the the casino since we're just gambling :P
ModestasV
ModestasV2w ago
honestly, that is one of the reasons why I find some interesting use-cases for Filament 😄 It always starts with what if...? for me
Jordy
JordyOP2w ago
now I need to figure out how to call the submit button :kekw:
->form([
...
Actions::make([
FormAction::make('start')
->hidden(fn(Get $get) => $get('amount_billed') == null || $get('presented_transport') == null)
->action(function (Order $record, Set $set, $livewire) {
$set('delivery_date_start', now()->format('Y-m-d H:i:s'));
//figure out how to call the submit button

}),
->form([
...
Actions::make([
FormAction::make('start')
->hidden(fn(Get $get) => $get('amount_billed') == null || $get('presented_transport') == null)
->action(function (Order $record, Set $set, $livewire) {
$set('delivery_date_start', now()->format('Y-m-d H:i:s'));
//figure out how to call the submit button

}),
ModestasV
ModestasV2w ago
this one for sure should be available via $livewire probably something like $livewire->call(..)
LeandroFerreira
sorry for the delay.. following your code, if you are using a table action, I think it should be $livewire->callMountedTableAction()
Jordy
JordyOP2w ago
no worries, already fixed by moving the actions into the form so they update following ->live() https://discord.com/channels/883083792112300104/1333748055585067131/1333768518864474134
LeandroFerreira
it makes sense 👍
Jordy
JordyOP2w ago
throws call() doesnt exists on the page instance tried the dirty aproach straight from v2 but this doesnt work either (sadge)
$record->update(
$this->form->getState()
);

$this->closeActionModal();
$record->update(
$this->form->getState()
);

$this->closeActionModal();
LeandroFerreira
is it a table action?
Jordy
JordyOP2w ago
its complicated 😂 its a Filament\Forms\Components\Actions\Action inside of a the Form of a \Filament\Tables\Actions\Action
LeandroFerreira
try $livewire->callMountedTableAction() to submit the form
Jordy
JordyOP2w ago
it does close the modal but doesnt save the data to db.. weird nvm im stupid, hadnt defined said action yet Thanks alot @LeandroFerreira !

Did you find this page helpful?