Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use vex.dialog.confirm in a if() statement? #42

Closed
liubin opened this issue Jan 20, 2014 · 1 comment
Closed

How can I use vex.dialog.confirm in a if() statement? #42

liubin opened this issue Jan 20, 2014 · 1 comment

Comments

@liubin
Copy link

liubin commented Jan 20, 2014

Hi

First thanks for your easy-to-use and beautiful VEX dialog, and now I'm using it in our project.

But I wonder if can I use it in a if statement like the traditional confirm() function in JavaScript, I want to send request only when user clicked YES/OK. I tried and failed.

Is there any method to achieve this task?

BR.

@zackbloom
Copy link
Contributor

The native confirm and prompt dialogs have a strange property in that they pause execution of all javascript on the page until they are responded to. That ability allows you to do something like:

value = confirm();

The javascript interpreter will pause on that line until the confirm dialog is submitted.

Vex, being made of just javascript, not the magic dust the browser is made of, cannot do that, so we have to use a callback:

vex.dialog.confirm({
  message: 'Are you absolutely sure you want to destroy the alien planet?',
  callback: function(value) {
    return console.log(value ? 'Successfully destroyed the planet.' : 'Chicken.');
  }
});

Your callback function will be called with the response when the user has entered a value and clicked ok.

Ultimately, this is better, as we usually don't want to lock up the entire process while we're waiting for some input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants