Search code examples
javascriptjqueryangularjspopupbootbox

bootbox 4.4 how to alert with different button label


i see in bootbox v3 documentation you can change the label by using below method bootbox.alert(str message, str label, fn callback) Custom button text, callback invoked on dismissal,

However on version 4.4 this method does not seem to work, how can i get to use a custom button label on alert message


Solution

  • You can override the text for any dialog, using the buttons option (which does require you to use an options object to setup your dialog). For example, here's a custom alert:

    $(function() {
      bootbox.alert({
        message: 'I have a custom OK button',
        buttons: {
          ok: {
            label: 'Right on!'
          }
        }
      })
    })
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>

    For confirm and prompt, you can override confirm and cancel as buttons.