I am designing a login form. when the user clicks on login button a modal should popup.
I have used livewire emitsTo
event.
<button wire:click="$emitTo('login','loginModalOpen')" class="text-primary px-6 py-[13px] font-bold">Sign in</button>.
This is the code for button.
namespace AppLivewireV2Auth;
use LivewireComponent;
class Login extends Component
{
public bool $open = false;
protected $listeners = [
'loginModalOpen' => 'openLoginModal'
];
public function openLoginModal()
{
// $this->open = true;
info("we are here") ;
// $this->emit('loginModalOpen');
$this->dispatchBrowserEvent('loginModalOpen');
}
public function render()
{
return view('livewire.v2.auth.login')
->extends('v2.layouts.app')
->section('content');
}
}
<div
x-data="{ open: false }"
@loginModalOpen.window="open = true"
x-show="open"
id="signin-modal"
class="relative z-[51]"
aria-labelledby="modal-title"
role="dialog"
aria-modal="true"
onclick="modalClose()"
>
...............................................
</div>
this is how it is given in livewire/v2/auth/login.blade.php.
But, the modal is not coming. i have checked console and there is’nt any visible errors.
should i include something more ?
2
Answers
Why dont you use actions for that
And in your blade you simply put