Add a default value to an input that doesn't exist in my resource

I have price and percentage columns in my resource. When i update price or percentage inputs it updates my result input. This input is disabled. It's just shows result. But when i add default value to result it's not shows result in my edit form. I want to show initial value. How can i solve this?
6 Replies
Mohamed Melouk
use formatStateUsing instead of default
ZedoX
ZedoX2y ago
Please share your code
Biostate
BiostateOP2y ago
TextInput::make('result') ->numeric() ->required() ->default(function (\Closure $get) { return $get('price') * $get('percentage') ; }) ->disabled(true), Throws error Method Filament\Forms\Components\TextInput::formatStateUsing does not exist.
ZedoX
ZedoX2y ago
Use ->afterStateUpdated on both price and percentage and $set result
Biostate
BiostateOP2y ago
Yeah i know that. I already added but when i enter the edit page it's empty. After i update or percentage it's updated. Init value is empty otherwise.
ZedoX
ZedoX2y ago
Then do the same in ->afterStateHydrated
Want results from more Discord servers?
Add your server