I’m working with Laravel 5.8 and Sweet Alert & I wanted to get some data from an input field:
$(document).on('click', '#discountbtn', function(e) {
e.preventDefault();
let form = $(this).parents('form');
swal({
title: "If you have discount code then write it down",
type: "warning",
allowEscapeKey: false,
allowOutsideClick: false,
showCancelButton: true,
animation: "slide-from-top",
confirmButtonColor: "#DD6B55",
confirmButtonText: "Submit",
cancelButtonText: "I dont have any",
showLoaderOnConfirm: true,
closeOnConfirm: false,
html: '<input id="swal-input2" class="swal2-input">',
preConfirm: function () {
return new Promise(function (resolve) {
resolve([
$('#swal-input2').val()
])
})
},
onOpen: function () {
$('#swal-input1').focus()
}
}).then((isConfirm) => {
if (typeof isConfirm.value === 'undefined') {
swal("User pressed on Cancel Button")
}else{
// get result
}
});
});
So now this alert pop up on the screen and I want to get the result and do something with it:

But I don’t know how to get the result in this case!
Also if I try this, then I couldn’t find out user pressed on Cancel button (I Don’t have any) or “Submit” button:
.then(function (result) {
swal(result)
}).catch(swal.noop)
});
So how can I get result from user input if he clicks on Submit button?