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


#1

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?


#2

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


#3

@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: {}
  });
});

#4

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:


#5

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


#6

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.


#7

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