Question

In Bootbox 3.2.0, I was able to use confirm with strings passed as below:

bootbox.confirm(
    confirm_string, 
    cancel_string, 
    yes_string,
    function(r) {           
        if (r) {
            //do something
        }
    }
);

I am upgrading to 4.1.0 and I got errors with the above function call.

According to the documentation (http://bootboxjs.com/documentation.html) of Bootbox 4.1.0, there are two ways to call confirm:

bootbox.confirm(str message, fn callback)    
bootbox.confirm(object options)

I tested the fist way with the message string and a callback function and it works. For the second way, I was able to pass an object as follows:

{
  message: message_string
  callback: function(r) {
    //do something
  }
}

How can I pass strings for OK, Cancel buttons in the second way?

Thanks and regards.

Was it helpful?

Solution 3

You can use the "Custom dialog" (bootbox.dialog) to change these strings.

bootbox.dialog({
  message: "Custom message",
  title: "Custom title",
  buttons: {
    danger: {
      label: "Custom Cancel",
      className: "btn-danger",
      callback: function() {
        //do something
      }
    },
    main: {
      label: "Custom OK",
      className: "btn-primary",
      callback: function() {
        //do something else
      }
    }
  }
});

OTHER TIPS

As an alternative this can also be done directly with bootbox.confirm, like so:

bootbox.confirm({
    buttons: {
        confirm: {
            label: 'Localized confirm text',
            className: 'confirm-button-class'
        },
        cancel: {
            label: 'Localized cancel text',
            className: 'cancel-button-class'
        }
    },
    message: 'Your message',
    callback: function(result) {
        console.log(result);
    },
    title: "You can also add a title",
});

OR use localization - option, to change ALL Buttons per Default:

    bootbox.setDefaults({
          /**
           * @optional String
           * @default: en
           * which locale settings to use to translate the three
           * standard button labels: OK, CONFIRM, CANCEL
           */
          locale: "de"
    });

seen: http://bootboxjs.com/documentation.html, "Helper methods"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top