Update viewfield state with placeholder addition values

Hello everyone, I wish update a viewfield state with dynamic placeholder values operation (the last line of the screenshot).
Forms\Components\Placeholder::make('vcpu_cost')
->content(fn (Get $get): string => Number::currency(
Vcpu::where('id', '=', $get('vcpu_id'))
->first()->price,
'EUR',
App::currentLocale())
),
Forms\Components\Placeholder::make('ram_cost')
->content(fn (Get $get): string => Number::currency(
Ram::where('id', '=', $get('ram_id'))
->first()->price,
'EUR',
App::currentLocale())
),
Forms\Components\Placeholder::make('disk_space_cost')
->content(fn (Get $get): string => Number::currency(
$get('disk_space_cost_per_go') * (int) $get('disk_space'),
'EUR',
App::currentLocale())
),
Forms\Components\ViewField::make('total_cost')
->label(__('vmc.total_cost'))
->disabled()
->inlineLabel()
->view('filament.forms.components.horizontal-label-price'),
// I think I have to add something here...
Forms\Components\Placeholder::make('vcpu_cost')
->content(fn (Get $get): string => Number::currency(
Vcpu::where('id', '=', $get('vcpu_id'))
->first()->price,
'EUR',
App::currentLocale())
),
Forms\Components\Placeholder::make('ram_cost')
->content(fn (Get $get): string => Number::currency(
Ram::where('id', '=', $get('ram_id'))
->first()->price,
'EUR',
App::currentLocale())
),
Forms\Components\Placeholder::make('disk_space_cost')
->content(fn (Get $get): string => Number::currency(
$get('disk_space_cost_per_go') * (int) $get('disk_space'),
'EUR',
App::currentLocale())
),
Forms\Components\ViewField::make('total_cost')
->label(__('vmc.total_cost'))
->disabled()
->inlineLabel()
->view('filament.forms.components.horizontal-label-price'),
// I think I have to add something here...
How can I afford this?
No description
2 Replies
dissto
dissto3w ago
You probably want to work with the state or the record and do your calculations! 🤔
adysone
adysone3w ago
$getRecord can only provide "real" inputs value, but not placeholders values. I'm trying to find a workaround and use hidden fields instead right now, but my hidden fields won't update, I don't know why (but I'm working on it) I don't know how update my viewField state as soon as juste one of the three fields are updated There is nothing simpler than using afterStateUpdated() and afterStateHydrated() on all my fields ? I mean, on placeholders, you can juste use the content() method with a Closure and it will be updated as soon as a live() field is updated. Can't we do the same on viewField, or maybe other fields ?