Trigger an Event from a custom field blade file
I've been trying to solve this for hours now, without any luck.
I have a custom field component with a button in it. When clicking on that button, I want to be able to update a state field in the parent form.
I've tried everything,
#[On
attribute, $listeners
and even registerListeners
but nothing is being able to caputre the event sent from the blade file.
I'm using wire:click="$dispatch('reshuffle')"
to dispatch that event.11 Replies
I've tried everything, #[On attribute, $listeners and even registerListeners but nothing is being able to caputre the event sent from the blade file.Where did you put this? On the page?
@Dennis Koch In the blade file of the custom field component
This is my structure:
Custom action
EliminationMatchesAction
with the following simplified schema:
TournamentRoundPreviewField is a custom Filed component with it's own blade file. In that blade file, I'm showing a table of next rounds and a "Refresh Button".
I want when the "Refresh Button" from the blade file is clicked, to change the value of the seed
TextInput of the EliminationMatchesAction form.
I know I could add an action to the EliminationMatchesAction form schema, like:
But I want to use the button from the bladeIn the blade file of the custom field componentIn the Blade file? Those need to be in a Livewire component
Can I attach a Livewire component directly as a field of a form? Or I must wrap it with a field first?
Pages are Livewire components.
Not sure whether fields can be
Alright I'll try to convert it to a livewire component. Thank's @Dennis Koch
I'll report back here when I solve it
You could just put methods you want to call on the action
Also you could use
$set
to set a value, not 100% sure how to access this in the Blade File.It seems that there is no direct way for a blade file of a custom field to trigger events back to it's component
Yes, because the field component is not a Livewire component. That's why I say you need to put it on the Page components
Ok now I understand my problem.
My custom Modal:
EliminationMatchesAction
is not a Livewire component, so it's not listening for dispatched events.
If I place the #[On]
listener in my EditRecord page, it gets triggered:
However, placing the #[On()]
listener inside of EliminationMatchesAction doesn't get triggered.
I need to update the state ( $set ) of a field (the seed) which is inside of EliminationMatchesAction, on that event, which seems impossible?