Aug 26, 2022
0
Level 2
On Before event, with exceptions
Hi everyone!
I have a form and I would like to implement a function that alert the user if they are going to another page. So far I have implemented the following global event listener:
Inertia.on('before',(event) => {
Swal.fire({
icon: "error",
title: "Existen datos sin guardar,desea abandonar la página?",
showCancelButton: true,
cancelButtonColor: "red",
cancelButtonText: "CANCELAR",
showConfirmButton: true,
confirmButtonColor: "#003E86",
confirmButtonText: "A C E P T A R"
})
event.preventDefault()
})
It works ok but the problem is that the form is a 3 step form and in each step it does a post to the backend to validate the data, so when you try to do that the event listener is fired and it shouldn't in this case.
So the question would be: how can I tell to the event listener to fire all times except in some action?
Thank you!
Please or to participate in this conversation.