Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MatildaSmets's avatar

Livewire alert isn't shown

Since Livewire can't display the same error again after form submission, I tried using JavaScript to dispatch an event to my JavaScript to show the alert. Problem is, it doesn't show the alert. The console log says Error event received: ['Ongeldig e-mailadres of wachtwoord.'] so it's passed to JavaScript properly, but the alert isn't shown.

This is my backend (partially):

This is my alert.js file:

document.addEventListener("DOMContentLoaded", function () {
    Livewire.on("error", (bericht) => {
        console.log("Error event received:", bericht);
        alert();
    });

    Livewire.on("succes", (bericht) => {
        console.log("Success event received:", bericht);
        alert();
    });

    function alert()
    {
        const alert_container = document.getElementById("alert-container");

        alert_container.innerHTML = "test";
    }
});

And this is my frontend (partially):

<div>
    <form wire:submit.prevent="inloggen">
        @csrf

        <div id="alert-container"></div>
   </form>
</div>

Does anyone know a solution for this issue and what's causing it?

0 likes
0 replies

Please or to participate in this conversation.