livewire component with event in form

hello everyone, I have inserted inside my form, a select and a livewire component that simply has to display a blade with data (html and css), which should update when the state of the select changes
->form([
Select::make('rating_id')
->prefix('Your choise')
->hiddenLabel()
->options($this->array_opts)
->required()
->reactive()
->afterStateUpdated(function (?string $state, ?string $old) {
$this->dispatch('my_event', rating_id: $state);
}),
Livewire::make(MyComponent::class, ['article_uuid' => $this->article_uuid, 'rating_id' => $this- >rating_id]),
])
->form([
Select::make('rating_id')
->prefix('Your choise')
->hiddenLabel()
->options($this->array_opts)
->required()
->reactive()
->afterStateUpdated(function (?string $state, ?string $old) {
$this->dispatch('my_event', rating_id: $state);
}),
Livewire::make(MyComponent::class, ['article_uuid' => $this->article_uuid, 'rating_id' => $this- >rating_id]),
])
to update the data of the MyComponent component I thought of using in the select afterStateUpdated $this->dispatch and in my livewire component
#[On('my_event')]
public function doSomething(string $rating_id): array
{
dd('ok');
//do something
}
#[On('my_event')]
public function doSomething(string $rating_id): array
{
dd('ok');
//do something
}
but it seems that the event is not listened, what am I doing wrong? thanks in advance
2 Replies
krekas
krekas2mo ago
on which class you are firing event and on which listening for it?
malebestia.
malebestia.OP2mo ago
it seems solved, the cause seems that inside my livewire component MyComponent::class I had not imported the class use Livewire\Attributes\On; used in the function #[On('my_event')] public function doSomething(string $rating_id): array { dd('ok'); //do something }
Want results from more Discord servers?
Add your server