Skip to content

how to trigger js event from livewire component? #3512

Closed Answered by lingtalfi
lingtalfi asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks, it helped a lot.

I had to adapt the code a little, but you got me thinking in the right direction.

For those in the same case: here is what i did.
I actually have two solutions:

The first one is using js as described:

First solution (using js)

My Livewire component php side:

class YourComponent extends Component
{
    public $photo = [];

    public function updatedPhoto()
    {
        $this->dispatch('photoUpdated', $this->photo);
    }

    // Rest of your component code...
}

For my livewire component i added the live property to force the update:

<livewire:media-library wire:model.live="photo" />

And to interact with it js side (in my blade component):

@script
<script>
  Live…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by lingtalfi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants