theunreal — 2014-01-09T09:07:12-05:00 — #1
I would like to add message verifcation in JS to ask the user "Are you sure you want to perform this action?" before it's making the action (in my case - removing some user details in PHP)
how I can do that?
pullo — 2014-01-09T09:49:02-05:00 — #2
You could use a confirm dialogue.
I have heard you say these are only for debugging purposes.
Is there an alternative that I have overlooked?
davidfregoli — 2014-01-09T11:03:24-05:00 — #3
confirm, alert, prompt and the likes block the browser and therefore are considered bad practice by many (not to demonize, I use them myself sometimes, but it's nice to be aware of it and follow better standars if the project allows it). of course they're super good for debugging/prototyping.
the alternative is simply an html modal/popup.
obviously it can't be used the same way since it's not-blocking and "asyncronous" so you'd have to refactor using callbacks, or, if you're super cool, promises
pullo — 2014-01-09T11:16:50-05:00 — #4
So what is a better way of confirming if a user really wants to perform an action (for example to ensure that they didn't click on 'delete' by mistake)?
I see you updated your answer to include HTML modal. Could you point me to an example of what you mean?
system — 2014-01-09T11:28:16-05:00 — #5
You can omit putting a submit type button for the form. Then you use a normal button type instead, display a dialog on click, and only .submit() the form if the dialog returns the sure value.
It helps if the confirmation dialog is modal: http://jqueryui.com/dialog/#modal-message.
davidfregoli — 2014-01-09T11:30:44-05:00 — #6
the better way is simply to show a custom, relatively positioned div (and maybe fade the rest of the page to black) with buttons, like
or making your own.
If you do things smartly you will keep a single one in the DOM and change its message and buttons labels as you need, while binding the appropriate function callbacks to handle the pressing of the buttons.
felgall — 2014-01-09T15:25:28-05:00 — #7
That's definitely the right way to do it.
stomme_poes — 2014-01-09T15:32:48-05:00 — #8
I use built-in alerts and the such quite often, because making modals accessible, especially for screen readers, is still eating the hottest chicken vindaloo and pooping it out in an endless trial of fire and dirty poophacks.
Some day the modal dialog will be built into the browser where it belongs, instead of the long string of cringeworthy a11y-hacks and manual keyboard focus it is now.
That said, I'm always pleased when I run across some plugin thingie where someone took the time to do all the hacks for me. I'm looking for a lighbox-container for dialogs and popups and have seen a few now with keyboard-traps, default-escapes, multi-language keybindings (even control keys often aren't the same code across different-language keyboards, so even listening for ENTER can be complicated depending on who you're supporting) and the like.
But I'm still of the opinion that developers on the front shouldn't have to be building these wheels over and over again.
Also, the fact that everything stops until that confirm/alert/whatever is dealt with, is sometimes exactly what you want, which should also help you decide which type you'd want to use.