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.
Solution:
Livewire::make(CheckOutInfoList::class, fn (Get $get) => [
'field_1' => $get('field_1'),
]),
Livewire::make(CheckOutInfoList::class, fn (Get $get) => [
'field_1' => $get('field_1'),
]),
...
Jump to solution
3 Replies
acabust
acabustOP2w ago
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
LeandroFerreira
Livewire::make(CheckOutInfoList::class, fn (Get $get) => [
'field_1' => $get('field_1'),
]),
Livewire::make(CheckOutInfoList::class, fn (Get $get) => [
'field_1' => $get('field_1'),
]),
namespace App\Livewire;

use Livewire\Attributes\Reactive;
use Livewire\Component;

class CheckOutInfoList extends Component
{
#[Reactive]
public ?string $field_1;

public function render()
{
return view('livewire.check-out-info-list');
}
}
namespace App\Livewire;

use Livewire\Attributes\Reactive;
use Livewire\Component;

class CheckOutInfoList extends Component
{
#[Reactive]
public ?string $field_1;

public function render()
{
return view('livewire.check-out-info-list');
}
}
<div>
{{ $field_1 }}
</div>
<div>
{{ $field_1 }}
</div>
acabust
acabustOP2w ago
Thank you very much! Great help
Want results from more Discord servers?
Add your server