FilamentF
Filament15mo ago
Matthew

Create Action using different forms

Anybody got any suggestions on how to go about using a different form dependent on the type of record being added.

I've got a table which holds different types of records, with a load of options that get stored in a Json format as a single column.

Could therefore do with a different 'form' for each option.

I can bring up an initial modal with a type select, but not sure how to advance that into a createAction with a dynamic form choice based upon the initial selection.

Tried this:

    public static function getTableHeaderActions() : array
    {
        return [
            Action::make('chooseType')
                ->label('Choose Type of Element')
                ->form([
                    Select::make('cdf_type')
                        ->label('Element Type')
                        ->required()
                        ->live() 
                        ->options(enumCdfType::getDropDownSelectOptions()),
                ])
                ->action(function (array $data) {
                    $selectedType = $data['cdf_type'];

                    return CreateAction::make('newElement')
                        ->form(ClientDocFieldsForm::getFields(selectedType: $selectedType));

                }),
        ];

    }


But it doesn't fire a new modal.
Was this page helpful?