Photo from Chile

A Cool jQuery Plugin - FastConfirm

I was working on the Engage app for cf.Objective() and I wanted to quickly add a confirmation dialog to the delete link for proposals. Now I'm not a particularly advanced jQuery developer, but I do know that there are a lot of people out there who are, and many of them have written plugins to help us lazier folks get things done. Through the power of Google I found a jQuery Plugins Page that lists all plugins that have been tagged with the term confirm. Wanting something quick and easy, I was drawn to one called Fast Confirm.

I checked out the demo and read through the docs, then saw some comments on the bottom of the docs page that suggested precisely how to implement the plugin for my exact use case. Within 10 minutes I had my confirmation dialog up and running! Here's the code:

view plain print about
1<link type="text/css" href="/css/jquery.fastconfirm.css" rel="stylesheet" />
2<script type="text/javascript" src="/js/jquery.fastconfirm.js"></script>
3<script type="text/javascript">
4    $(function(){
5        $(".confirm").click(function() {
6            $(this).fastConfirm({
7                position: "right",
8                onProceed: function(trigger) {
9                    window.location.href=$(trigger).attr("href");
10                },
11                onCancel: function(trigger) {
12                }
13            });
14            return false;
15        });
16    });
17</script>

With the above script on my page, all I have to do is add a class of confirm to any anchor tag and I'll get a confirmation dialog whenever the anchor is clicked.

The plugin does allow you to change the question asked in the dialog, as well as a number of other options, but I was happy to accept the default of "Are you sure?". I think this is a great, simple plugin. Kudos to Pierre-Jean Parra for writing it and contributing it to the community.

TweetBacks
Comments
You say you like this plugin, but...are you sure??? ;-)))

Thanks for sharing.
# Posted By soundstruck | 12/2/10 8:36 PM
I like it to, but the buttons are a bit ugly. may i replace them.
# Posted By maertsch | 12/3/10 7:59 AM
The buttons are pure css so it should be easy to change their appearance.
# Posted By Bob Silverberg | 12/3/10 8:22 AM
Very nice. Thanks for the tip. I was reading your blog for more insights on CF9 ORM and got a bonus!
# Posted By Bob Chesley | 12/4/10 12:03 PM
This was helpful thanks, in more recent jQuery its

$(".confirm").on("click",function() {

Which works even if you change the content of the page dynamically
# Posted By Michael | 8/22/12 11:42 AM