get a field value in an action
How can i get the value of a form field inside an action?
This is my action:
Actions\Action::make('gespreksverslag_herschrijven')
->label('Gespreksverslag herschrijven')
->icon('heroicon-o-pencil')
->action(function(Get $get){
$originalText = $get('conversation_report_original');
$service = new RewriteTextWithGPTService();
$rewrittenText = $service->handle(static::$prompt, $originalText);
$this->form->fill(['conversation_report_gpt' => $rewrittenText]);
}),
$get() will give m the following error: Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization
It must be simple, but I can't find it in the docs. What am i missing?
This is my action:
Actions\Action::make('gespreksverslag_herschrijven')
->label('Gespreksverslag herschrijven')
->icon('heroicon-o-pencil')
->action(function(Get $get){
$originalText = $get('conversation_report_original');
$service = new RewriteTextWithGPTService();
$rewrittenText = $service->handle(static::$prompt, $originalText);
$this->form->fill(['conversation_report_gpt' => $rewrittenText]);
}),
$get() will give m the following error: Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization
It must be simple, but I can't find it in the docs. What am i missing?
Solution
Found it. I can use $this->data to retrieve the form values
Actions\Action::make('gespreksverslag_herschrijven')
->label('Gespreksverslag herschrijven')
->icon('heroicon-o-pencil')
->action(function(){
$originalText = $this->data['conversation_report_original'];
$service = new RewriteTextWithGPTService();
$rewrittenText = $service->handle(static::$prompt, $originalText);
$this->form->fill(['conversation_report_gpt' => $rewrittenText]);
}),
Actions\Action::make('gespreksverslag_herschrijven')
->label('Gespreksverslag herschrijven')
->icon('heroicon-o-pencil')
->action(function(){
$originalText = $this->data['conversation_report_original'];
$service = new RewriteTextWithGPTService();
$rewrittenText = $service->handle(static::$prompt, $originalText);
$this->form->fill(['conversation_report_gpt' => $rewrittenText]);
}),