how to use model dialogue instead of confirm api in preSubmit handler
how to use model dialogue instead of confirm api in preSubmit handler

in my editor preSubmit handler, I call confirm like this:
profile_editor.on('preSubmit', function (e, data, action) {
return confirm(Are you sure want to change profile ?
);
});
It works fine. But I want to use a customized modal instead of calling "confirm" function. like this:
profile_editor.on('preSubmit', function (e, data, action) {
return $("#warningModal").modal()
});
It doesn't work because the modal() immediately returns back before waiting for user's action.
Any ideas? Thanks!
Answers
What you need to do here is make use of a
Promise
.As you say,
preSubmit
is synchronous, but you can return a Promise to make it wait until the Promise is fulfilled - e.g.:I don't know how the modal you are using works or its API, but hopefully that will help to some degree.
Allan
Thanks Allan! I am still struggling with the modal+promise. I am using the bootstrap modal. It still does not work.
The modal html code like this:
The js code is like this:
You have:
But
initSubmit
doesn't accept a Promise in return. You need to usepreSubmit
like I suggested for a Promise return to work. If you could try that, hopefully that will then do the job.Allan
Thanks Allan!
It seems the preSubmit has a bug processing the Promise. Just for test purpose, I have simplified the code to always return false, but it actually always submitted. Could you please take a look what is wrong with my code?
I agree - my apologies for this error. It can be seen in this demo if you run the following in your console:
Let me look into this one and get back to you.
Allan
allan, thanks for looking into this. Please let me know if you have any updates.
This has now been addressed and will be in the next release - which is likely to be tomorrow.
Colin
colin, is this fix released? if so, is it in which file and which version?
No, it wasn't. The last release was 1.9.5, on the 18th September. We are hoping to make a release in the next couple of weeks. I'll make a note to update this thread when that happens,
Colin
Hi,
Apologies for the long delay on this one. That is 1.9.6 now available.
Regards,
Allan