F
Filament16mo ago
qcol

afterStateHydrated() doesn't work?

When I try to use the example from the documentation, I get an error. What am I doing wrong? TypeError App\Filament\Resources\TestResource::App\Filament\Resources\{closure}(): Argument #2 ($state) must be of type string, null given, called in ......./vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35
3 Replies
LeandroFerreira
LeandroFerreira16mo ago
?string $state
awcodes
awcodes16mo ago
$state should typically be typed as mixed. Because it could technically be anything.
qcol
qcolOP15mo ago
OK, I was doing a copy/paste from the documentation so it's a small bug in the documentation? This example already with the fix (?string) causes the "name" field to change only during initialization (so when the form is read from the database). After changing this field manually, nothing happens. Is this how afterStateHydrated() works? Back to this topic I'm stuck on: https://discord.com/channels/883083792112300104/1143657714086580264/1144196863428399177 ...this code also does not make the total field change every time the qty or price changes: return $form ->schema([ TextInput::make('qty')->live(), TextInput::make('price')->live(), TextInput::make('total') ->required() ->afterStateHydrated(function (Get $get, TextInput $component) { $component->state($get('qty') * $get('price')); }) ]); Should this work or am I still doing something wrong?
Want results from more Discord servers?
Add your server