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
5 Replies
dissto
dissto6mo ago
You probably want to work with the state or the record and do your calculations! 🤔
Adysone
AdysoneOP6mo 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 ?
Ali
Ali2w ago
Hello, did you find a solution for this ? i'm trying to get the value of my placeholder and also update it. the workaround would just be a disabled TextInput, but that's not what the design
Firebat
Firebat2w ago
put ->live and use afterStateUpdated if i got right your need, you should only do afterStateUpdated on one field and after that it would change the others and disabled fields need to have "dehydrated" so that they will save the value inside
Adysone
AdysoneOP7d ago
Hi, @Ali I'm sorry, I didn't see your message before. I made a custom component that fits to my need, I didn't manage to make it work with standard component Placeholder.
Want results from more Discord servers?
Add your server