Modal Promise Example

Regarding: bootsnipp.com/snippets/bXkn6

Is there any issue with this implementation? I am new to promises.

adityarar () - 6 years ago - Reply 0


It works how I would expect it to:

It logs "yay" in the console when you click the "Save Changes" button in the modal.

It logs "boo" if you click "Cancel" in the modal.

It logs "boo" if you click the close X in the corner of the modal.

It logs "boo" if you click off of the modal.

I've noticed if you click to view the HTML or JS portions of the snippet and go back to the Preview it will throw and error. That might just be related to how this particular snippet works in Bootsnips preview. Refreshing the page fixes it.

If you're asking about whether this is the right way to do modal popups I'd say it depends. I wrote this a long time ago, but I believe I was trying out promises because I needed a way to trigger custom code depending on what action was taken in a modal and a simple confirmation box wasn't going to cut it.

If all you need is to display a modal with information and allow the user to close the modal then this is definitely overkill. Bootstrap handles that kind of thing on its own and you don't need promises in that case.

Here's some more info on Promises in general: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

alefrost (1) - 6 years ago - Reply 1