mendozal
mendozal
FFilament
Created by mendozal on 8/30/2024 in #❓┊help
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?
3 replies