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?
$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:Jump to 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')...
7 Replies
The form itself is in a default resource create or editpage
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('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
$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
You should use
->action(function (array $data)
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); }) ,
$company=$data('companyname'); return route('panel-bill',$company); }) ,
@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);}) ,
} 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);}) ,