#passing action arguments into nested actions
19 messages · Page 1 of 1 (latest)
public function testAction(): Action
{
return Action::make('day_action')
->label('Day Clicked')
->modalHeading('Choose an action')
->modalSubmitAction(false) // disable default "Save" button
->modalFooterActionsAlignment('center')
->modalWidth('md')
->mountUsing(function (array $arguments) {
dd($arguments);
})
->modalFooterActions([
// 1. View Day button
// 2. Add Availability button
Action::make('addAvailability')
->label('Add Availability')
->color('success')
->mountUsing(function (array $arguments, Form $form) {
// Prefill if needed
dd($this->mountedActionArguments());
$form->fill([
'start_date' => $arguments['date'] ?? now()->toDateString(),
'end_date' => $arguments['date'] ?? now()->toDateString(),
]);
})
->form($this->getAvailabilityForm()) // extract your giant schema into a helper
->action(function (array $data) {
// Save the availability here
// dd($data);
}),
]);
}```
Trimmed for character limit
you mean makeModalSubmitAction?
https://filamentphp.com/docs/4.x/actions/modals#adding-an-extra-modal-action-button-to-the-footer
Ah, that could be it. my plan is having a click event that opens a modal, im shown 2 buttons, 1 to view the date I clicked in a calendar, and another that would update the modal form or redirect to another modal form to submit hours
I just couldnt get the arrguments passed into the action to go into the footer action
yes, I think makeModalSubmitAction. Try it
Just on my lunch break now, will be back on in a few hours to give it a try, Ill leave this ticket open for now. Thank you 🙂
no no, try it right now
just kidding 😅
if it doesn't work, tag me and share the code that you are using ✌️
Yes boss! 🫡 🤣
Got like 3 projects on the go right now, its hectic. And I need to speak to the boss about alocating time to update our boilerplate to v4 - im running out of energy 🤣
From what I can see, that isnt working -> Is this just expecting data from the initial action?
Where im calling the action
$this->mountAction('test', ['date' => $carbon, 'record' => $this->instructor->getKey()]); // Example time, adjust as needed
Then I need those keys/values in the footer action
Could share the whole code on gist?
So I managed to add record, but still cant get the initial argument in. I can only share bits of it due to NDA
I've sent it via DM
public function dayAction(): Action
{
return Action::make('day')
->label('Day Clicked')
->modal()
->modalSubmitAction(false)
->extraModalFooterActions(function (Action $action): array {
return [
Action::make('addAvailability')
->color('success')
->fillForm(fn (): array => [
'date' => $action->getArguments()['date'] ?? null,
'user' => $action->getArguments()['record'] ?? null,
])
->form([
TextInput::make('date'),
Select::make('user')
->options([
1 => 'User 1',
2 => 'User 2',
]),
])
->action(function (array $data) {
dd($data);
}),
];
});
}
and use $this->mountAction('day', ['date' => now(), 'record' => 1])
don't forget this: The method must share the exact same name as the action, or the name followed by Action
So that did show the form, but when I try to use a function that returns form components, it doesnt show?
public function dayAction(): Action
{
return Action::make('day')
->label('Day Clicked')
->modal()
->modalSubmitAction(false)
->extraModalFooterActions(function (Action $action): array {
return [
Action::make('addAvailability')
->color('success')
->record($this->instructor)
->fillForm(fn(): array => [
'start_date' => $action->getArguments()['date'] ?? null,
])
->form(
[self::getInstructorAvailabilityFormComponent()]
)
->action(function (array $data) {
// dd($data);
}),
];
});
}
And the snippet of the function
public static function getInstructorAvailabilityFormComponent(): Component
{
return Forms\Components\Section::make('Instructor Availability')
->description('Set available working hours for instructors')
->schema([
Forms\Components\Repeater::make('instructor_availabilities')
->relationship('instructorAvailabilities', function ($query) {
return $query->where('auto_generated', false);
})
->collapsible()
->label('Availability Periods')
->collapsed()
->collapsible()
->schema([
Surely its not because im using sections and grids etc?
Oh, apparently it is, but also made me realise that I dont even need the form im trying to use 🤣
So your solution was spot on