I am trying to customize bootboxjs.prompt options, but it seems that it doesn't allow an options object as a parameter
This is the example from http://bootboxjs.com/index.html#api
bootbox.prompt("What is your name?", function(result) {
if (result === null) {
Example.show("Prompt dismissed");
} else {
Example.show("Hi <b>"+result+"</b>");
}
});
This is what I am trying to pass:
var promptOptions = {
title: "Custom label",
buttons: {
confirm: {
label: "Save"
}
}
};
bootbox.prompt(promptOptions, function(result) {
if (result === null) {
console.log("Prompt dismissed");
} else {
console.log("Hi "+result);
}
});
How can I customize the title and buttons label ?
Pressing the ESC key or clicking close () dismisses the dialog and invokes the callback as if the user had clicked the Cancel button.
js is a small JavaScript library which allows you to create programmatic dialog boxes using Bootstrap modals, without having to worry about creating, managing, or removing any of the required DOM elements or JavaScript event handlers.
You will be able to make a custom prompt using custom dialogs. The only thing you have to know is that the message string you give to bootbox doesn't have to be plain text. It can be HTML, so you can put your own prompt in a custom bootbox dialog.
What you are trying to do is this (using Bootbox 4.x):
bootbox.dialog({
message: "First name:<input type='text' id='first_name'>",
title: "Custom label",
buttons: {
main: {
label: "Save",
className: "btn-primary",
callback: function() {
console.log("Hi "+ $('#first_name').val());
}
}
}
});
bootbox.prompt
only takes one parameter if you want to pass an object with your custom labels. So in order to make it work, you have to put your callback in your config object:
var promptOptions = {
title: "Custom label",
buttons: {
confirm: {
label: "Save"
}
},
callback: function(result) {
if (result === null) {
console.log("Prompt dismissed");
} else {
console.log("Hi "+result);
}
}
};
bootbox.prompt(promptOptions);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With