F
Filament7mo ago
rajul

How to dispatch filament form data using blade $dispatch method

When I am trying to $dispatch an event to send filament form data, it is not sending updated form data. However If use dispatch inside livewire component I am able to get updated data. But by calling dispatch in livewire component will result in server call. I am trying to avoid server call. This is not send updated data:
<div>
<div class="p-4">
<form wire:submit="create">
{{ $this->form }}
<button
class="bg-gray-800 text-white rounded p-2 mt-2"
x-on:click="
$dispatch('jobsupdated', { data: {{ json_encode($this->form->getState()) }} })
"
>
Submit
</button>
</form>

</div>
</div>
<div>
<div class="p-4">
<form wire:submit="create">
{{ $this->form }}
<button
class="bg-gray-800 text-white rounded p-2 mt-2"
x-on:click="
$dispatch('jobsupdated', { data: {{ json_encode($this->form->getState()) }} })
"
>
Submit
</button>
</form>

</div>
</div>
However this is sending correct data:
public function create(): void
{
$this->dispatch('jobsupdated', data : $this->form->getState());
}
public function create(): void
{
$this->dispatch('jobsupdated', data : $this->form->getState());
}
Please let me know if there is a way to send updated form data from blade file itself to avoid server roundtrip.
2 Replies
LeandroFerreira
LeandroFerreira7mo ago
A Livewire event is used to communicate between different components. Are you sure you need it? I’m curious why you want to use $dispatch if it will ultimately result in a network request.
rajul
rajulOP7mo ago
I have a custom field where user can select multiple multiple jobs from list of jobs, as list can be long so I am showing that list in a model and when user selects all interested jobs I dispatches all selected jobs back to custom field’s state where I listen for event ‘jobsupdated’ , I want to use browser event $dispatch instead of livewire $dispatch to avoid server roundtrip.
Want results from more Discord servers?
Add your server