skip to Main Content

I have a button on my blade that calls a select method, this method emitted an event but it is not arriving

Button blade:

<div class="ml-auto">
    <button class="br-button secondary circle" type="button" aria-label="Selecionar" wire:click="selecionar({{ json_encode($user) }})">
                    <i class="fas fa-arrow-right"></i>
    </button>
</div>

Method Select: which is inside the search component

public function selecionar($user)
{
        $this->emit('userSel', $user);
        $this->buscaNome = "";
        $this->usuarios = [];

}

Method userSel: which is inside the create component

protected $listeners = ['userSel'];

public function userSel($user)
{
    $this->state = $user;
}

I’ve already tried to issue directly from the blade.

2

Answers


  1. Check the network tab. emit should create a 2nd request (Livewire2) and you can check whether the listener gets executed:

    public function userSel($user)
    {
        dd($user);
        $this->state = $user;
    }
    

    In your case the create component should be present on the page

    Login or Signup to reply.
  2. Modify the {{ json_encode($user) }} of the function
    to '{{ json_encode($user) }}'

    wire:click="selecionar('{{ json_encode($user) }}')"
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search