#passing action arguments into nested actions

19 messages · Page 1 of 1 (latest)

kindred shadow
#

I have an action with footer actions. In those footer actions I need $arguments from the mountUsing on the parent. Not sure how to obtain those arguments in the child?

flint dirgeBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

kindred shadow
#
    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
kindred shadow
#

I just couldnt get the arrguments passed into the action to go into the footer action

faint salmon
kindred shadow
faint salmon
kindred shadow
kindred shadow
faint salmon
kindred shadow
#

I've sent it via DM

faint salmon
# kindred shadow 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

kindred shadow
# faint salmon ```php public function dayAction(): Action { return Action::make('day') ...

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