Steve
Steve

Reputation: 176

Bootstrap Dialog Global options?

I have many dialog popups spread across many pages, each utilizing BoostrapDialog

BootstrapDialog.show({...});
or 
var x = new BootstrapDialog({...});

I want to add the "closeByBackdrop: true" option to all of them.
Is there a way to define some default options? I'm thinking along the same lines as jQuery's ajaxSettings() where you can set global options (but still override them in each specific instance if necessary)

$.ajaxSetup ({
    cache: false,
    error: function(x, t, m){
        alert("Generic Error");
    }
});  

I cant't find any information remotely related to a global options setter anywhere...which leads me to think there is no such thing. wondering if someone knows of this... or even better has implemented their own way of achieving this.

The obvious solution is to manually go through all my dialogs and add the option manually, but since this is the preferred way they should ALL work, i'd like to not have to specify it for every instance.

The other solution would be to re code them all to accept my own options object, and just extend that object for each instance:

$(document).ready(function(){

    modalOptions = {...};
});    

function openDialogX(){

    var dialogXOptions = modalOptions;
    dialogXOptions.buttons = [...];
    dialogXOptions.title = "...";
    dialogXOptions.message = "...";

    var dialogX = new BootstrapDialog(dialogXOptions);
}

It would be nice to not have to re-code them all to accept a custom options object.

TL;DR:
Is there a BoostrapDialog equivalent to jQuery's ajaxSettup() for redefining default options. If not, what solutions have you used to achieve this (if at all).

Upvotes: 1

Views: 1090

Answers (1)

davidkonrad
davidkonrad

Reputation: 85558

You do have a BootstrapDialog.defaultOptions around line 231 in the master repo. Use that to modify the defaults to whatever you need :

$.extend( BootstrapDialog.defaultOptions, {
  closable: true,
  closeByBackdrop: true,
  autodestroy: false
} );

and take benefit of the new settings in all dialogs :

var myDialog = new BootstrapDialog({
  title: 'Example',
  message: 'Sample text'
}).open()

demo -> http://jsfiddle.net/ffj6r1b6/ (try change closeByBackdrop to false and re-run)

Upvotes: 1

Related Questions