Programmatically Create Alert/Confirm/Prompt Dialog Boxes Using jQuery - boodal

Programmatically Create Alert/Confirm/Prompt Dialog Boxes Using jQuery - boodal
File Size: 10.6 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Boodal is a jQuery/Bootstrap plugin which lets you programmatically create customizable alert/confirm/prompt dialog boxes without having to write any HTML markup.

Based on Bootstrap 4's modal component.

How to use it:

1. Download and insert the JavaScript file boodal.min.js after jQuery & Bootstrap.

<script src="/path/to/jquery.slim.min.js"></script>
<script src="/path/to/bootstrap.min.js"></script>
<script src="dist/boodal.min.js"></script>

2. Create an alert dialog using the boodal.alert method.

boodal.alert({
  
  // alert title
  'title': 'Alert Title',

  // alert message
  'body': 'Alert Message',

  // close button
  'cancel': 'Close',

  // ok button
  'ok': 'Close',

  // CSS class for ok button
  'ok.class': 'btn-danger',

  // triggered when you click the ok button
  'ok.callback': function(){
    console.log('Dismissed');
  },

  // 'static'. default 'static'
  'modal.backdrop': 'static', 

  // enable/disable keyboard interactions
  'modal.keyboard': false,

  // auto focus the dialog
  'modal.focus': true
  
});

3. Create a confirm dialog using the boodal.confirm method.

boodal.confirm({
  
  // confirm title
  'title': 'Confirm Title',

  // confirm message
  'body': 'Confirm Message',

  // cancel button
  'cancel': 'Cancel',

  // ok button
  'ok': 'Yes',

  // CSS class for ok button
  'ok.class': 'btn-primary',

  // CSS class for cancel button
  'cancel.class': 'btn-light'

  // triggered when you click the ok button
  'ok.callback': function(){
    console.log('Dismissed');
  },

  // triggered when you click the cancel button
  'cancel.callback': function(){}

  // 'static'. default 'static'
  'modal.backdrop': 'static', 

  // auto focus the dialog
  'modal.focus': true

});

4. Create a prompt dialog with a text field using the boodal.text method.

boodal.text({
  
  // prompt title
  'title': 'Prompt Title',

  // prompt message
  'body': 'Prompt Message',

  // close button
  'cancel': 'close',

  // default input value
  'val': 'Foo Bar', 
  
  // input placeholder
  'placeholder': 'Enter your name...',

  // additional attributes for the input field
  'attrs': {
    'class': 'first-class second-class',
    'id': 'my-id'
  },

  // ok button
  'ok': 'Save',

  // CSS class for ok button
  'ok.class': 'btn-success',

  // triggered when you click the ok button
  'ok.callback': function(result){
    console.log('result');
  },

  // triggered when you click the cancel button
  'cancel.callback': function(){}

  // 'static'. default 'static'
  'modal.backdrop': 'static', 

  // auto focus the dialog
  'modal.focus': true

  // auto focus the dialog
  'modal.focus': true

});

5. Create a prompt dialog with an email field using the boodal.email method.

boodal.email({
  
  // prompt title
  'title': 'Prompt Title',

  // prompt message
  'body': 'Prompt Message',

  // close button
  'cancel': 'close',

  // default input value
  'val': '[email protected]', 
  
  // input placeholder
  'placeholder': 'Enter your email...',

  // additional attributes for the input field
  'attrs': {
    'class': 'first-class second-class',
    'id': 'my-id'
  },

  // ok button
  'ok': 'Save',

  // CSS class for ok button
  'ok.class': 'btn-success',

  // triggered when you click the ok button
  'ok.callback': function(result){
    console.log('result');
  },

  // triggered when you click the cancel button
  'cancel.callback': function(){}

  // 'static'. default 'static'
  'modal.backdrop': 'static', 

  // show close button
  'modal.close': true

  // auto focus the dialog
  'modal.focus': true

});

6. Create a prompt dialog with a number input using the boodal.number method.

boodal.number({
  
  // prompt title
  'title': 'Prompt Title',

  // prompt message
  'body': 'Prompt Message',

  // close button
  'cancel': 'close',

  // default input value
  'val': '10', 
  
  // input placeholder
  'placeholder': 'Enter your number...',

  // additional attributes for the input field
  'attrs': {
    'class': 'first-class second-class',
    'id': 'my-id'
  },

  // ok button
  'ok': 'Save',

  // CSS class for ok button
  'ok.class': 'btn-success',

  // triggered when you click the ok button
  'ok.callback': function(result){
    console.log('result');
  },

  // triggered when you click the cancel button
  'cancel.callback': function(){}

  // 'static'. default 'static'
  'modal.backdrop': 'static', 

  // show close button
  'modal.close': true

  // auto focus the dialog
  'modal.focus': true

});

7. Create a prompt dialog with a select box using the boodal.select method.

boodal.select({
  
  // prompt title
  'title': 'Prompt Title',

  // prompt message
  'body': 'Prompt Message',

  // close button
  'cancel': 'close',

  // an array of options
  'options': ['jQuery', 'Script']

  // default select value
  'val': 'jQuery', 
  
  // placeholder
  'placeholder': 'Enter your number...',

  // additional attributes for the select box
  'attrs': {
    'class': 'first-class second-class',
    'id': 'my-id'
  },

  // ok button
  'ok': 'Save',

  // CSS class for ok button
  'ok.class': 'btn-success',

  // triggered when you click the ok button
  'ok.callback': function(result){
    console.log('result');
  },

  // triggered when you click the cancel button
  'cancel.callback': function(){}

  // 'static'. default 'static'
  'modal.backdrop': 'static', 

  // show close button
  'modal.close': true

  // auto focus the dialog
  'modal.focus': true

});

8. Create a prompt dialog with checkboxes using the boodal.checkbox method.

boodal.checkbox({
  
  // prompt title
  'title': 'Prompt Title',

  // prompt message
  'body': 'Prompt Message',

  // close button
  'cancel': 'close',

  // an array of checkbox options
  'options': ['jQuery', 'Script']

  // default value
  'val': 'jQuery', 
  
  // placeholder
  'placeholder': 'Enter your number...',

  // additional attributes for checkboxes
  'attrs': {
    'class': 'first-class second-class',
    'id': 'my-id'
  },

  // ok button
  'ok': 'Save',

  // CSS class for ok button
  'ok.class': 'btn-success',

  // triggered when you click the ok button
  'ok.callback': function(result){
    console.log('result');
  },

  // triggered when you click the cancel button
  'cancel.callback': function(){}

  // 'static'. default 'static'
  'modal.backdrop': 'static', 

  // show close button
  'modal.close': true

  // auto focus the dialog
  'modal.focus': true

});

9. Create a prompt dialog with radio buttons using the boodal.radio method.

boodal.radio({
  
  // prompt title
  'title': 'Prompt Title',

  // prompt message
  'body': 'Prompt Message',

  // close button
  'cancel': 'close',

  // an array of radio buttons
  'options': ['jQuery', 'Script']

  // default value
  'val': 'jQuery', 
  
  // placeholder
  'placeholder': 'Enter your number...',

  // additional attributes for radio buttons
  'attrs': {
    'class': 'first-class second-class',
    'id': 'my-id'
  },

  // ok button
  'ok': 'Save',

  // CSS class for ok button
  'ok.class': 'btn-success',

  // triggered when you click the ok button
  'ok.callback': function(result){
    console.log('result');
  },

  // triggered when you click the cancel button
  'cancel.callback': function(){}

  // 'static'. default 'static'
  'modal.backdrop': 'static', 

  // show close button
  'modal.close': true

  // auto focus the dialog
  'modal.focus': true

});

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