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

285
Vistas
¿Cómo usar confirmar usando alerta dulce?

En este formulario de código se envía incluso si estoy haciendo clic en no

 document.querySelector('#from1').onsubmit = function(){ swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary file!", type: "warning", showCancelButton: true, confirmButtonColor: '#DD6B55', confirmButtonText: 'Yes, I am sure!', cancelButtonText: "No, cancel it!", closeOnConfirm: false, closeOnCancel: false }, function(isConfirm){ if (isConfirm){ swal("Shortlisted!", "Candidates are successfully shortlisted!", "success"); } else { swal("Cancelled", "Your imaginary file is safe :)", "error"); } }); };
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Deberá evitar el comportamiento predeterminado del formulario al enviarlo. Después de eso, deberá enviar el formulario mediante programación en caso de que se seleccione el botón Aceptar.

Así es como podría verse:

 document.querySelector('#from1').addEventListener('submit', function(e) { var form = this; e.preventDefault(); // <--- prevent form from submitting swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary file!", icon: "warning", buttons: [ 'No, cancel it!', 'Yes, I am sure!' ], dangerMode: true, }).then(function(isConfirm) { if (isConfirm) { swal({ title: 'Shortlisted!', text: 'Candidates are successfully shortlisted!', icon: 'success' }).then(function() { form.submit(); // <--- submit form programmatically }); } else { swal("Cancelled", "Your imaginary file is safe :)", "error"); } }) });

UPD. El ejemplo anterior utiliza la API de promesa sweetalert v2.x.

Demostración: http://plnkr.co/edit/YTY7PDs5Uh1XGUo9ic1s?p=preview

over 4 years ago · Santiago Trujillo Denunciar

0

document.querySelector('#from1').onsubmit = function(e){ swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary file!", type: "warning", showCancelButton: true, confirmButtonColor: '#DD6B55', confirmButtonText: 'Yes, I am sure!', cancelButtonText: "No, cancel it!", closeOnConfirm: false, closeOnCancel: false }, function(isConfirm){ if (isConfirm){ swal("Shortlisted!", "Candidates are successfully shortlisted!", "success"); } else { swal("Cancelled", "Your imaginary file is safe :)", "error"); e.preventDefault(); } }); };
over 4 years ago · Santiago Trujillo Denunciar

0

Necesitas usar la función then(), como esta

 swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary file!", type: "warning", showCancelButton: true, confirmButtonColor: '#DD6B55', confirmButtonText: 'Yes, I am sure!', cancelButtonText: "No, cancel it!" }).then( function () { /*Your Code Here*/ }, function () { return false; });
over 4 years ago · Santiago Trujillo 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