Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
SweetAlert isConfirm does not work properly

I want to show a Sweet Alert 2 confirm message to user after submitting the form like this:

<form id="myForm" data-flag="0" action="" method="POST">
   @csrf
   <input type="checkbox" id="btn-submit" name="wallet_checked" onchange="this.form.submit();">
</form>

As you can see I have used onchange="this.form.submit();" to submit the form without using submit button and it works fine.

Then I tried adding this as script for showing SweetAlert message to user:

 $(document).on('click', '#btn-submit', function(e) {
    e.preventDefault();
    let form = $(this).parents('form');
    swal(
        {
        title: "Attention!",
        text: "Are you sure you want to make this",
        type: "warning",
        allowEscapeKey: false,
        allowOutsideClick: false,
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes",
        cancelButtonText: "No",
        showLoaderOnConfirm: true,
        closeOnConfirm: false
    },

    function (isConfirm) {
        if (isConfirm) {
            console.log("YES");
        }
        return false;
    });
});

So the function shows Sweet Alert message on screen after clicking on the checkbox, but when I press on Yes button, it does not run console.log("YES");.

And this means that if (isConfirm) { at function (isConfirm) { is not working properly.

So how to solve this issue? What is wrong with isConfirm?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Change this to :

 $(document).on('click', '#btn-submit', function(e) {
    e.preventDefault();
    let form = $(this).parents('form');
    swal(
        {
        title: "Attention!",
        text: "Are you sure you want to make this",
        type: "warning",
        allowEscapeKey: false,
        allowOutsideClick: false,
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes",
        cancelButtonText: "No",
        showLoaderOnConfirm: true,
        closeOnConfirm: false
    })
    .then((isConfirm) => {
        if (isConfirm) {
            console.log("YES");
        }
        return false;
    });
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda