akvaskov's avatar

Get form schema of an action

Hi,

I have a table and one toolbar action

            ->toolbarActions([
                Action::make('settings')
                    ->form([
                        Fieldset::make('chahgeLogPeriodSettings')
                            ->label('Use stock change logs')
                            ->schema([
                                DatePicker::make('chahgeLogFromSetting')
                                    ->label('From')
                                    ->default(Carbon::today()->subDays(7)),
                                DatePicker::make('chahgeLogTillSetting')
                                    ->label('Till')
                                    ->default(Carbon::today()),
                            ])
                    ]),

I'm trying to get values from the form of the action:

protected function getTableQuery(): Builder
    {
        $actions = $this->getTable()->getToolbarActions();
        dump($action[0]);
    }

If I add dump($actions[0]), I see that it will be Action object and there is a schema inside it. But how to get a respective array of this schema? I tried $actions[0]->getSchema(), ->getSchemaComponents(), getSchemaContainer() but all useless. Everything returns null or a message that the method doesn't exists. Please help!

0 likes
1 reply
jaseofspades88's avatar

What problem are you trying to solve? Are you trying to get the schema for use elsewhere?

I imagine you're using v3 and older as the improvements to components and such in v4 solves this problem... however, I would recommend you simply abstract out the fields you need into a static method on a class. ToolbarActionForm or something, which has a static get method, which returns the array of the components you require.

Please or to participate in this conversation.