This SweetAlert works successfully upon the Form submitting:
$('#upload-form').on('submit',function(e){
e.preventDefault();
var form = $('form');
swal.fire({
title: "Are you sure?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, submit it!",
closeOnConfirm: false
}, function(isConfirm){
console.log("sdfsf");
if (isConfirm) form.submit();
});
});
however, it doesnât display for longer than two seconds, before the Form automatically submits.
The SweetAlert is supposed to stay displayed and allow the confirm button to be selected to proceed.
(this is different than my other posting, in that this code is not in the BeforeSend function - thanks for the replies).
Any assistance is welcomedâŚ
(It was suggested to make the Submit button a button that opens the alert, and make the Formâs submit-btn button the swal confirmButtonâŚbut Iâm not sure how to do that (but Iâve tried))
Thanks for your message.
upon Form submit, a confirm dialog box appears, I wouldnât say that the dialog code submits the Form, because itâs not displayed long enough for someone to click the displayed dialog box choices, either 'Yes, submit it" or âCancelâ.
it was suggested trying having the submit button not submit the form, have it be a regular button, not a form submit button, so then, when that regular button is clicked, make it SweetAlert Swal.fire, and then make the âyes, submit itâ be the submit button. But I havenât been able to get that correct, in my attempts at switching those buttons.
⌠i would say it does? Cause you wrote those exact words into it?
Thatâs not whats making it submit now, but itâs going to be a problem in the immediate future.
From what your previous thread said, iâm guessing youâve still got code lingering around listening to the original form submit and its firing on this one. Impossible to tell without seeing the full page.
so⌠#upload-form is a div.
a div will never fire an onsubmit event⌠at least, it shouldnt be.
Your form is submitting itself, before the alert can intervene. Trigger off of (and prevent default from) the actual form.
Or dont even make the button in the form an actual submit button, and have the button execute the alert and submit. Which is probably the better route.
$('#upload-form').on('btn-submit',function(e){
âbtn-submitâ isnt an event type, so this code will never fire.
change to $('#submit-btn').on('click',function(e){
var form = $('form');
Too vague - youâve got multiple forms on the page, so this is going to find-and-fire all of them. var form = $('.pt_upld_page_frm');
and upon proceeding with an upload, the dialog box displays when the Submit button is clicked, and it successfully stays open until the dialog box button choice âCancelâ is selected, and the dialog box closes/disappears. Thatâs a big improvement. Much thanks.
However, when the other dialog box button choice âYes, submit it!â is selected the dialog box closes/disappears, and the Form isnât submitted. Upon clicking the Submit button again, the dialog box opens again.
I look forward to your comments and any help with getting the âYes, submit it!â button to submit the Form.
where it shows when the file is actually uploaded the redirect is to the home page.
So, somehow the sweetAlert isnât uploading and redirecting properly.
well since youâre taking control of the submit flow anyway, iâd just use ajaxSubmit in the then instead of setting up the form with ajaxForm and then relying on the secondary flow of submitting.
I greatly appreciate your reply and suggestion, I just donât know how to do that from a code standpoint. Not sure how to âuse ajaxSubmit in the thenâ. Iâd be grateful for any additional guidance with that coding
Thank you again.
Tried sveral things without getting the code correct.
If anyone would like to provide an example of " take the options in your ajaxForm code, put it into an ajaxSubmit function instead, put that inside your button handler". the guidance would be greatly
appreciated.
Or should I ask which site I should be looking at to find the last person that wrote your code for you so that we know what it looks like now, considering youâve been posting this code for the last 2 years between this site, codingforum, reddit, phpfreaksâŚ
You seem to be using code you found somewhere that doesnât do exactly what you want it to do and are trying to change the codes function without understanding that found code.
The first step in this situation is understanding the code you have. Without understanding that code how can you hope to change it to do what you want it to do.
My understanding is that you want a message displayed for a predetermined time when submitting a form.
To display a message before submitting the form using jQuery is either impossible or very difficult. Doing it in vanilla jScript is easy, so are you ready to toss jQuery aside and use current best practice jScript?
and it doesnât display the Alert, but it does successfully submit/upload the file.
The goal is to have the âYes, submit itâ to actually submit
Any suggestions are welcomed