Created
June 25, 2020 18:18
-
-
Save ahamilton9/cfe22b1499b2b6bed529fb5ffa1017f4 to your computer and use it in GitHub Desktop.
Prompt Promise for Modals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function promptPromise(message) { | |
return new Promise(function(resolve, reject) { | |
// Open the modal and pass it message, resolve, and reject | |
// Have the modal call resolve(<response if you need one>) on confirm, reject() on cancel | |
}); | |
} | |
var button = document.getElementById('action'); | |
button.addEventListener('click', function() { | |
promptPromise('What is your name?') | |
.then(function(responseIfYouNeedOne) { | |
// resolve (confirm) code, hide modal, do stuff | |
}, | |
function() { | |
// reject (cancel) code, hide modal | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment