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?
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')...
Jump to solution
7 Replies
Patrick
PatrickOP9mo ago
The form itself is in a default resource create or editpage
Solution
Patrick
Patrick9mo ago
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]); }),
hashim199
hashim1997mo ago
Actions\Action::make('PanelInvoice')->form([ TextInput::make('companyname') ->label('Company Name'), DatePicker::make('from')->default(null), DatePicker::make('to')->default(null), ])->url(function (Get $get) {

$data=$get('companyname'); dd($get('companyname')); return route('panel-bill',$data); }, shouldOpenInNewTab: true) , error: Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization @Patrick1989 @Dennis Koch
Dennis Koch
Dennis Koch7mo ago
You should use ->action(function (array $data)
hashim199
hashim1997mo ago
Error: Array callback must have exactly two elements Actions\Action::make('PanelInvoice')->form([ TextInput::make('companyname') ->label('Company Name'), DatePicker::make('from')->default(null), DatePicker::make('to')->default(null), ])->action(function (array $data) {

$company=$data('companyname'); return route('panel-bill',$company); }) ,
hashim199
hashim1997mo ago
@Dennis Koch sorry to bother you but i am stuck if i eturn route('panel-invoice', $parameters['companyname']); it shows no error just reload now if i return return route('panel-invoice', $parameters); error Missing required parameter for [Route: panel-invoice] [URI: panel-invoice/{data}] [Missing parameter: data]. Route::get('/panel-invoice/{data}', [BillPanelReports::class, 'createInvoice'])->name('panel-invoice'); public function createInvoice( $data) { dd($data);
} Actions\Action::make('PanelInvoice')->form([ TextInput::make('companyname') ->label('Company Name'), DatePicker::make('from')->default(null), DatePicker::make('to')->default(null), ])->action(function (array $data) { $parameters = [ 'companyname' => $data['companyname'], 'from'=>$data['from'], 'to'=>$data['to'], // other parameters if needed ]; return route('panel-invoice', $parameters);}) ,
Want results from more Discord servers?
Add your server