How to Pass Dynamic Data from Filament Form to Livewire Component for Price Calculation
I'm trying to create a Livewire component that displays the price of a product within a Filament form. The form allows users to manipulate several select fields (to change color, model, etc.), and each change can affect the price.
My goal is to display the updated price whenever the form values change. I've been using this documentation page as a reference: https://filamentphp.com/docs/3.x/forms/advanced#inserting-livewire-components-into-a-form
Currently, I can pass fixed values to my Livewire component like this:
Forms\Components\Livewire::make(CalculPrixSejour::class, [
'sejour_id' => '33';
]),
However, it seems impossible to use closures directly. This doesn't work:
Forms\Components\Livewire::make(CalculPrixSejour::class, [
'sejour_id' => function (Get $get) {
return $get('sejour_id');
},
]),
It seems odd that I can't pass anything other than fixed values. I must be missing something in the documentation.
3 Replies
ive also tried this:
Livewire::make(CheckOutInfoList::class, function (Get $get) {
//here you can do some necessary calculation before passing to the component
return [
'variable_name1' => $get('field_1'),
'variable_name2' => $get('field_2'),
//more fields
];
})
On component:
public $field1;
public $field2;
//others fields
public function mount($variable_name1, $variable_name2, //others variables){
$this->field1 = $variable_name1;
$this->field2 = $variable_name2;
//others variables
}
However:
Property [$expeditor_id] not found on component: [app.filament.resources.order-resource.pages.create-order]
When attempting to set public attribute '$expeditor_id' on 'create-order' component is no longer reactive.
Solution
Thank you very much! Great help