top | item 8487642

Sweet Alert for Bootstrap – Blends nicely with any Bootstrap based project

95 points| lipis | 11 years ago |lipis.github.io | reply

36 comments

order
[+] akvlad|11 years ago|reply
I agree this does look sweet, however this is not a replacement for alert. window.alert() is a blocking function, it prevents further code to be interpreted while the alert or prompt is open.
[+] jessedhillon|11 years ago|reply
Sweet Alert came up before and people made this same pedantic and unimaginative addition -- I honestly think this comment serves only to let everyone know that the commenter understands the Javascript execution model. That the thread stops while a native alert is shown is not quite a bug, but I'd argue not a desired feature either.

But given that window.alert has (apparently) two functions:

- Display a message to a user

- Block javascipt execution until a button is pressed

This is a great replacement for those who are using it for #1, which in my experience, is probably >99% of its usage in the wild. If you're using window.alert to, say, synchronize the beginning of an event with a user click this probably will work just fine too. If you need the world to stop until a button is pressed, I'd sooner guess that your application is written poorly.

[+] cmpb|11 years ago|reply
There are of course more functional approaches to delaying execution of code in Javascript, e.g. by using a callback (which this library supports).
[+] mandeepj|11 years ago|reply
Please have "Esc" key cancel\close the dialog box. It is the inherent behavior please do not break it.
[+] coreyja|11 years ago|reply
This seems to working for my. "Esc" closes all the examples. Mac OSX Yosemite - Chrome 38
[+] mk4p|11 years ago|reply
I met the most interesting guy once. He was a professor at Columbia and a consultant for Wall Street, helping design UIs for traders.

He explained how we process and prioritize visual cues -- how, if an element expands equally to the left AND right of our field of vision, it gets highest priority because it resembles an object heading toward our face.

For that reason, he avoided this design for everything except the highest-priority events.

Not crapping on your library -- it looks really nice :) But in general, I think it's worth considering if it's necessary to demand users' attention all over the place. I think information overload isn't solely in the content we consume but how it's presented.

[+] warble|11 years ago|reply
I've been seeing a few of these libs pop up on HN lately. Apparently there's some sort of need here that people are trying to fill, it's just not clear to me what it is.

There are legitamite suggestions that blocking UI paradigms are bad, but they're very useful at times. I'm not arguing either, as I think each has their place (although I tend to avoid blocking personally if I can)

My real question is why now?

[+] dangrossman|11 years ago|reply
Lots of people on HN develop web apps but aren't great designers, and nifty little libraries like this make our work look better than our own design skill would normally allow. I think it's that simple -- they're not being upvoted for any deep reason relating to UX best practices.
[+] execat|11 years ago|reply
The way the alert comes in is very annoying.

The homepage doesn't tell me if I can customize the animation.

[+] aidos|11 years ago|reply
It would be nice if it was possible to select / copy the message in the box. Sometimes you get a message that you want to copy / paste to someone (email, chat, etc) and it's annoying to have to type it out again.
[+] JoshTriplett|11 years ago|reply
Nice style, and I appreciate that I can hit Esc to dismiss most of the dialogs, though unfortunately not all of them.

As another commenter said, I do wish that clicking outside of it had the same effect, but that may have more to do with what sites typically abuse these kinds of boxes for ("Alert! Sign up to our..." (no go away)).

One issue I noticed: there's a race condition in the second-to-last example ('...and by passing a parameter, you can execute something else for "Cancel".'), where if you hit escape quickly enough as the box gets launched, the cancellation handler does not run.

[+] gadders|11 years ago|reply
Re: your second point, on the original Sweet Alert page that this is based on it has this parameter:

allowOutsideClick - If set to true, the user can dismiss the modal by clicking outside it.

[+] decentrality|11 years ago|reply
This really needs to be added to http://jsdelivr.com so we can package it in with existing CDN calls.

There seem to be very sparse examples of how to deploy the library properly, only to implement it.

Visually great. Cool how there's the ability to catch responses and work in the same modal further.

[+] dangrossman|11 years ago|reply
Anyone can add something to jsDelivr, not just the library author. You can add it yourself if you'd like them to host it.
[+] yournemesis|11 years ago|reply
I still don't get why javascript developers put so much effort into a library and don't provide tests for it.
[+] FreakyT|11 years ago|reply
I usually find alert libraries boring, but these are really cool -- I particularly enjoy the icon drawing animations.
[+] unknown|11 years ago|reply

[deleted]

[+] danneu|11 years ago|reply

    swal({
      title: "Click outside to close",
      allowOutsideClick: true
    })
[+] amatera|11 years ago|reply
swal("Here's a message!") !== alert("Here's a message!")

Am i wrong or is a replacement not something which replace the original function? (beside the blocking aspect of an alert). Looks beautiful anyway :)

[+] j_syk|11 years ago|reply
Looks cool. I'd like to see [esc] to close dialog. And is it a safe default to have [enter] perform the action especially on warning and danger? (just a thought)
[+] emodendroket|11 years ago|reply
Why would I use this instead of the built-in modals? Seems like it does the same thing.
[+] danneu|11 years ago|reply
When you want a nice looking off-the-shelf feedback modal with a simple API without depending on Bootstrap JS and the entirety of jQuery.
[+] NDizzle|11 years ago|reply
Just in time for Halloween! Scary, jarring alerts.
[+] iand675|11 years ago|reply
The icon animations are really slick!