Examples
Currently viewing examples for version 1.x.
Currently viewing examples for version 1.x.
The examples below attempt to demonstrate the myriad ways in which you can use Bootprompt.js. Where functionality amongst the dialogs is nearly identical, the example will indicate to which functions the example applies.
bootprompt.alert("This is the default alert!");
bootprompt.alert("This is an alert with a callback!", function(){ console.log('This was logged in the callback!'); });
bootprompt.alert({
message: "This is an alert with a callback!",
callback: function () {
console.log('This was logged in the callback!');
}
})
Also applies to: Confirm, Prompt, Custom
bootprompt.alert({
message: "This is the small alert!",
size: 'small'
});
Requires Bootstrap 3.1.0 or newer.
Also applies to: Confirm, Prompt, Custom
bootprompt.alert({
message: "This is the large alert!",
size: 'large'
});
Requires Bootstrap 3.1.0 or newer.
Also applies to: Confirm, Prompt, Custom
bootprompt.alert({
message: "This is an alert with additional classes!",
className: 'rubberBand animated'
});
Also applies to: Confirm, Prompt, Custom
bootprompt.alert({
message: "This alert can be dismissed by clicking on the background!",
backdrop: true
});
Also applies to: Confirm, Prompt, Custom
bootprompt.alert({
message: "This alert uses the Arabic locale!",
locale: 'ar'
});
bootprompt.confirm("This is the default confirm!", function(result){ console.log('This was logged in the callback: ' + result); });
Also applies to: Alert, Prompt, Custom
bootprompt.confirm({
message: "This is a confirm with custom button text and color! Do you like it?",
buttons: {
confirm: {
label: 'Yes',
className: 'btn-success'
},
cancel: {
label: 'No',
className: 'btn-danger'
}
},
callback: function (result) {
console.log('This was logged in the callback: ' + result);
}
});
Also applies to: Alert, Prompt, Custom
bootprompt.confirm({
title: "Destroy planet?",
message: "Do you want to activate the Deathstar now? This cannot be undone.",
buttons: {
cancel: {
label: '<i class="fa fa-times"></i> Cancel'
},
confirm: {
label: '<i class="fa fa-check"></i> Confirm'
}
},
callback: function (result) {
console.log('This was logged in the callback: ' + result);
}
});
Also applies to: Alert, Prompt, Custom
var locale = $('#locales').val();
bootprompt.confirm({
message: "This confirm uses the selected locale. Were the labels what you expected?",
locale: locale,
callback: function (result) {
Example.show('This was logged in the callback: ' + result);
}
});
Please note: prompt requires the title
option (when using the options object). You may use the message
option,
but the prompt result will not include any form inputs from your message.
bootprompt.prompt("This is the default prompt!", function(result){ console.log(result); });
If you want to style the input, you can target the .bootprompt-input-text
class.
var locale = {
OK: 'I Suppose',
CONFIRM: 'Go Ahead',
CANCEL: 'Maybe Not'
};
bootprompt.addLocale('custom', locale);
bootprompt.prompt({
title: "This is a prompt with a custom locale! What do you think?",
locale: 'custom',
callback: function (result) {
Example.show('This was logged in the callback: ' + result);
}
});
bootprompt.prompt({
title: "This is a prompt with a set of checkbox inputs!",
value: ['1', '3'],
inputType: 'checkbox',
inputOptions: [{
text: 'Choice One',
value: '1',
},
{
text: 'Choice Two',
value: '2',
},
{
text: 'Choice Three',
value: '3',
}],
callback: function (result) {
console.log(result);
}
});
Checkboxes are nested in an element with the class .bootprompt-checkbox-list
.
If you want to style the individual checkbox inputs, you can target the .bootprompt-input-checkbox
class.
message
value
bootprompt.prompt({
title: "This is a prompt with a set of radio inputs!",
message: '<p>Please select an option below:</p>',
inputType: 'radio',
inputOptions: [
{
text: 'Choice One',
value: '1',
},
{
text: 'Choice Two',
value: '2',
},
{
text: 'Choice Three',
value: '3',
}
],
callback: function (result) {
console.log(result);
}
});
Radio buttons are nested in an element with the class .bootprompt-radiobutton-list
.
If you want to style the individual radio inputs, you can target the .bootprompt-input-radio
class.
When using the radio
option, the first radio button
will be checked if value
is missing or does not match an inputOptions
value.
Requires browser support: http://caniuse.com/#feat=input-datetime
bootprompt.prompt({
title: "This is a prompt with a date input!",
inputType: 'date',
callback: function (result) {
console.log(result);
}
});
If you want to style the input, you can target the .bootprompt-input-date
class.
Requires browser support: http://caniuse.com/#feat=email
bootprompt.prompt({
title: "This is a prompt with an email input!",
inputType: 'email',
callback: function (result) {
console.log(result);
}
});
If you want to style the input, you can target the .bootprompt-input-email
class.
Requires browser support: http://caniuse.com/#feat=input-number
bootprompt.prompt({
title: "This is a prompt with a number input!",
inputType: 'number',
callback: function (result) {
console.log(result);
}
});
If you want to style the input, you can target the .bootprompt-input-number
class.
bootprompt.prompt({
title: "This is a prompt with a password input!",
inputType: 'password',
callback: function (result) {
console.log(result);
}
});
If you want to style the input, you can target the .bootprompt-input-password
class.
bootprompt.prompt({
title: "This is a prompt with select!",
inputType: 'select',
inputOptions: [
{
text: 'Choose one...',
value: '',
},
{
text: 'Choice One',
value: '1',
},
{
text: 'Choice Two',
value: '2',
},
{
text: 'Choice Three',
value: '3',
}
],
callback: function (result) {
console.log(result);
}
});
If you want to style the select, you can target the .bootprompt-input-select
class.
bootprompt.prompt({
title: "This is a prompt with a textarea!",
inputType: 'textarea',
callback: function (result) {
console.log(result);
}
});
If you want to style the textarea, you can target the .bootprompt-input-textarea
class.
Requires browser support: http://caniuse.com/#feat=input-datetime
bootprompt.prompt({
title: "This is a prompt with a time input!",
inputType: 'time',
callback: function (result) {
console.log(result);
}
});
If you want to style the input, you can target the .bootprompt-input-time
class.
Requires browser support: http://caniuse.com/#feat=input-range
bootprompt.prompt({
title: "This is a prompt with a range input!",
inputType: 'range',
min: 0,
max: 100,
step: 5,
value: 35,
callback: function (result) {
Example.show('This was logged in the callback: ' + result);
}
});
If you want to style the input, you can target the .bootprompt-input-range
class.
Please note: Custom dialogs accept only one argument: an options object. The only required property of the options object is message
.
var dialog = bootprompt.dialog({
message: '<p class="text-center mb-0"><i class="fa fa-spin fa-cog"></i> Please wait while we do something...</p>',
closeButton: false
});
// do something in the background
dialog.modal('hide');
Also applies to: Alert, Confirm, Prompt
var dialog = bootprompt.dialog({
title: 'A custom dialog with init',
message: '<p><i class="fa fa-spin fa-spinner"></i> Loading...</p>'
});
dialog.init(function(){
setTimeout(function(){
dialog.find('.bootprompt-body').html('I was loaded after the dialog was shown!');
}, 3000);
});
var dialog = bootprompt.dialog({
title: 'A custom dialog with buttons and callbacks',
message: "<p>This dialog has buttons. Each button has it's own callback function.</p>",
size: 'large',
buttons: {
cancel: {
label: "I'm a cancel button!",
className: 'btn-danger',
callback: function(){
Example.show('Custom cancel clicked');
}
},
noclose: {
label: "I don't close the modal!",
className: 'btn-warning',
callback: function(){
Example.show('Custom button clicked');
return false;
}
},
ok: {
label: "I'm an OK button!",
className: 'btn-info',
callback: function(){
Example.show('Custom OK clicked');
}
}
}
});