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"); } }); };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
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(); } }); }; 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; });