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
use
formatStateUsing
instead of default
Please share your code
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.
Use
->afterStateUpdated
on both price and percentage and $set
resultYeah 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.
Then do the same in
->afterStateHydrated