jQuery Plugin To Confirm Actions By Typing Strings - safeConfirm

File Size: 15.8 KB
Views Total: 598
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
jQuery Plugin To Confirm Actions By Typing Strings - safeConfirm

safeConfirm is a JQuery plugin to enhance the native JavaScript confirm method that enables the user to confirm certain action by typing specified strings in a confirm dialog when triggered. It's great to prevent the user from suddenly deleting or sending something on the webpage. Similar to the World of Warcraft's 'Type delete to delete' character delete confirm dialog.

How to use it:

1. Add the jQuery safeConfirm plugin to the html page after you've loaded jQuery library.

<script src="//code.jquery.com/jquery.min.js"></script>
<script src="safeConfirm.js"></script>

2. Create an action button that will trigger a confirm dialog.

<a href="#" class='safeConfirm'>Delete</a>

3. Call the function the action button and specify the message to be displayed in the confirm dialog.

$('.safeConfirm').safeConfirm({
  title:'Are you sure?'
});

4. Change the default confirm text.

$('.safeConfirm').safeConfirm({
  title:'Are you sure?',
  confirmationText: 'delete',
});

5. Execute a callback after you type the correct string in the confirm dialog.

$('.safeConfirm').safeConfirm({
  title:'Are you sure?',
  confirmationText: 'delete',
  callback: function(){
    // do something
  }
});

6. You can also specify the ID and name for each action button using HTML5 data attributes.

<a href="#" class='safeConfirm'
   data-id="1" 
   data-name="Delete 1"
   >Delete</a>
$('.safeConfirm').safeConfirm({

  // or {id}
  title:'Are you sure to delete the record "{name}"?',

});

This awesome jQuery plugin is developed by donaldhansen. For more Advanced Usages, please check the demo page or visit the official website.