© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
6 replies
Patrick

How to implement a dynamic form in an action

I would like to display fields based on a database entry.

I have this action:
Action::make('Opleiding inplannen')                
                ->form([
                    Select::make('education_id')
                    ->label('')
                    ->options(Education::orderBy('name', 'asc')->pluck('name', 'id'))
                    ->required()
                    ->live()
                    ->afterStateUpdated(fn (Select $component) => $component
                        ->getContainer()
                        ->getComponent('planningForm')
                        ->getChildComponentContainer()
                        ->fill()
                    ),
                    Grid::make(2)
                    ->schema(function(Get $get){
                        
                        $educationId = $get('education_id');
                        
                        if($educationId){                    
                            return Educations::getPlanningFormSchemaArray(
                                Education::find($educationId)
                            );
                        }
                        
                        return [];                    
                    })
                    ->key('planningForm')

                ])
                ->action(function(array $data){                    
                                        
                })
                ->slideOver()
                ->after(function($data){
                    $url = route('filament.admin.resources.education.edit', ['record' => $data['education_id']]).'?openPlanningForm=true';
                    return redirect($url);
                }),
Action::make('Opleiding inplannen')                
                ->form([
                    Select::make('education_id')
                    ->label('')
                    ->options(Education::orderBy('name', 'asc')->pluck('name', 'id'))
                    ->required()
                    ->live()
                    ->afterStateUpdated(fn (Select $component) => $component
                        ->getContainer()
                        ->getComponent('planningForm')
                        ->getChildComponentContainer()
                        ->fill()
                    ),
                    Grid::make(2)
                    ->schema(function(Get $get){
                        
                        $educationId = $get('education_id');
                        
                        if($educationId){                    
                            return Educations::getPlanningFormSchemaArray(
                                Education::find($educationId)
                            );
                        }
                        
                        return [];                    
                    })
                    ->key('planningForm')

                ])
                ->action(function(array $data){                    
                                        
                })
                ->slideOver()
                ->after(function($data){
                    $url = route('filament.admin.resources.education.edit', ['record' => $data['education_id']]).'?openPlanningForm=true';
                    return redirect($url);
                }),


Now the
Educations::getPlanningFormSchemaArray
Educations::getPlanningFormSchemaArray
returns an array with a schema

However, when i select an education the initial value just gets reset in the select instead of seeing the new form.
How can i do this?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Dynamic Form Publish Resource Action
FilamentFFilament / ❓┊help
13mo ago
Adding an Action to a Form Section?
FilamentFFilament / ❓┊help
3y ago
How to access an Action's form in its modalContentFooter()?
FilamentFFilament / ❓┊help
2y ago
Dynamic form creation for custom action
FilamentFFilament / ❓┊help
3y ago