How to prefill resource field and run some calculations

I have an Invoices resource that has an action redirecting to the Credit Notes resource passing the invoice_id parameter:
->action(fn($record) =>redirect()
->route('filament.admin.resources.credit-note.create',
['invoice_id' => $record->id ])
),
->action(fn($record) =>redirect()
->route('filament.admin.resources.credit-note.create',
['invoice_id' => $record->id ])
),
This is working file. In the Credit Notes resource I'm using default() to load that.
Select::make('invoice_id')
->default(fn() => request()->get('invoice_id'))
Select::make('invoice_id')
->default(fn() => request()->get('invoice_id'))
But when using normally, this select field does some calculations using the afterStateUpdate() method, calculating some totals and setting those values into other fields. My issue is that when prefilling the field using default(), those calculations are not triggered. I guess the afterStateUpdated doesn't run at that point. Is there a way to trigger the afterStateUpdated from the default() method? Or some other solution I'm not seeing?
1 Reply
mendozal
mendozal2mo ago
I just calculated those values in the calling action and passed them in this array
->action(fn($record) =>redirect()
->route('filament.admin.resources.credit-note.create',
['invoice_id' => $record->id,
'value_2' => 'xxx',
'value_3' => 'yyy' ])
),
->action(fn($record) =>redirect()
->route('filament.admin.resources.credit-note.create',
['invoice_id' => $record->id,
'value_2' => 'xxx',
'value_3' => 'yyy' ])
),
And loaded them using default() in the receiving resource.
Want results from more Discord servers?
Add your server