App.dialog.alert does not wait for OK confirm, to continue execution

app.dialog.alert does not wait for OK confirm, to continue execution …

In my case I want to run after alert dialog OK confirm the following lines of code execution… underneath…

if I use this:


app.dialog.alert('the record was deleted, you will be redirected to the main screen!');

setTimeout(function() {
                                     app.router.back('/home/', {
                                         ignoreCache: true,
                                         force: true,
                                         context: {}
                                     });

}, 1500);

in this sample the alert shows but disappear without waiting OK click and excecute the underneath code :


                                 setTimeout(function() {
                                     app.router.back('/home/', {
                                         ignoreCache: true,
                                         force: true,
                                         context: {}
                                     });

                                 }, 1500);

is there any wait to pause the alert so it has to wait OK click confirm to continue?

any ideas for this issue?

Hi, you can use alert callback fnc

app.dialog.alert(text, title, callback)- create Alert Dialog and open it

text - string. Alert dialog text
title - string. Alert dialog title
callback - function. Optional. Callback function that will be executed after user clicks on Alert button

https://framework7.io/docs/dialog.html#alert

2 Likes

@pvtallulah is right, so it should be used as

app.dialog.alert('the record was deleted, you will be redirected to the main screen!', function () {
  app.router.back('/home/', {
    ignoreCache: true,
    force: true,
    context: {}
  });
});
1 Like

thank you i didn’t see that in the online documentation!!! weird!! maybe my cache was old!!! thank you for the link!!! and now it works! :slight_smile:

I found the documentation that talks about this… i did not see it before…
Thanks for the time to reply!! big thanks Vladimir!

By the way this is due to the fact that those alert or prompt browser native dialogs wait for user input pausing code execution making the code running synchronously, thats why you can capture the input valor. With framework 7 the code does not stops and keeps running because those alerts are not native but simulated to to fit the theme, this way it wont pause code, this requires the callback to be called after user input.

2 Likes

Am facing the same problem. Hope anyone here can help me too. Thanks in advance. Regards,