3 ms·
This is a nice implementation of an alert, but ideally you shouldn't ever need it. Alerts are a pretty horrible feature in a user's experience. Essentially they
by onion2k 12y ago
This is a nice implementation of an alert, but ideally you shouldn't ever need it. Alerts are a pretty horrible feature in a user's experience. Essentially they say "STOP WHAT YOU ARE DOING. THIS IS MORE IMPORTANT."
If something is that important then you'll usually want to give the user a choice from a set of options - e.g. if the user is doing something that can destroy data without the possibility of undoing their actions then you'll want a dialogue that asks them if they're sure. That should block all other interaction because it really is important. When the user has no input though, and there's nothing they can do but click 'ok', there's no need to use an alert. Just put a message on the screen that's high enough up the page's information hierarchy that they've very likely to see it. Make it sticky (so it's there until the user dismisses it, but doesn't block other actions) if it's something that they need to confirm that they've seen.
Don't force the user to do things your way. Guide the user, sure, but let them do things their way.
- jfaat 12y agoTrue but you can also use it with ok/cancel options, which I think fits the use case you mentioned when you said: > if the user is doing something that can destroy data without the possibility of undoing their actions then you'll want a dialogue that asks them if they're sure
- jcampbell1 12y agoAs far as I can tell, there are no callbacks. With javascript's confirm, you can do: if(confirm(....)) { doStuff() } else { cleanup() } This should at least have a callbacks for the different buttons. In terms of design, I don't like absolute vertical centering. It should be higher on the page. I use 1:2, or 1:1.6 for the top/bottom margin as my "default" modal centering.
- jfaat 12y agoOh wow, I just assumed those were tied to callbacks instead of just being a showCancelButton arg. The more I look into it the more underwhelmed I become.
- acdha 12y agoOne of the examples shows that they have a single callback function: http://tristanedwards.me/sweetalert http://tristanedwards.me/sweetalert Unfortunately, there's only one function so this isn't useful if you want to run code when the user cancels the dialog: https://github.com/t4t5/sweetalert/blob/750a0fd72c3beaa6d4d71336290def4d71d3ecd2/lib/sweet-alert.js#L298 https://github.com/t4t5/sweetalert/blob/750a0fd72c3beaa6d4d7...
- drzaiusapelord 12y ago>ok/cancel options, So, if I click OK am I acknowledging the alert to dismiss it or is performing an action? If I hit cancel am I canceling the alert or canceling the action? Its still terrible UI. Limiting the options to things like "ok" and "cancel" can be very confusing to the end user. Don't you agree? {OK} {Cancel}
- jfaat 12y agoI wasn't clear enough, but the confirmation button text can be customized. So as a quick example you could do something like this: Are you sure you want to delete? {Yes, delete thing X} {No, keep it} Would you still find that insufficient communication with the user? No sarcasm, genuinely interested to get your opinion.
- emergentcypher 12y agoCancelling the alert? That doesn't even make sense.
- michaelvkpdx 12y agoGenerally true, but I work on a system that has to comply with government regulations that basically say "this is the most important thing the user can possibly be doing. PERIOD." So alerts are pretty much a must for us, and the obnoxious interruptions help us make the regulators happy. Getting a nicer alert like this will make our customers a bit happier while still keeping us in compliance. But our use case is of course not standard. Usually alerts are like Satan.