This seems like a common usecase: I have a button that when clicked, will delete a record. I would like to pop up a dialog box asking, “are you sure you want to delete?”… and if they press ok, it will then continue the “clicked” action on the button, but if they press cancel, it will just return to the page and nothing will have happened.
With PHP, I would solve this as such:
<a onclick="if
(confirm('Are you sure you want to remove this record?'))
{window.location='https://mysite.com/?action=deleteRec&id=9851030'};" href="#" title="remove">
And then my delete rec action would do the delete, and redirect back to the original page, thus showing that the record is now gone.
But I can’t think of how this would be done in meteor. I found a few discussions that seemed to be very complicated.
this one:
went on for a while in a chat, and I’m not sure if they solved it or not.
This doesn’t answer your question, but poses another question that perhaps you should answer first: Do you really want confirmation or are you actually after undo?
Once I thought about it, I realised alot of my use cases called for the latter.
@ralpheiligan : thanks!.. that’s the example I needed, but as I suspected, it’s a lot of work to build the template for the modal popup, and then to write a handler for the click event on the “Yes” button on the dialog, etc. I was hoping it could be made easier — which it probably could if someone had time to build a package…
@mordrax: thanks! … your point is very well taken, and I have implemented that exact suggestion. I decided to perform the “delete” action right away without confirmation, and just mark the record as “deleted” … I haven’t decided yet how to allow undeletes, but I’m going down that path none the less.
The easiest and most decent looking solution is to use Sweet Alert. You can check if they hit yes or no in the callback and then run the code. This also won’t block like a regular alert will:
Thank you for the suggestions… I am going with the “undo” option, but in the future, if I need a confirmation popup, this thread will be a good source of info.