How to change the default bootbox OK button name?

Asked

Viewed 581 times

0

I am using the bootbox in my application and would like to know how to change the default name of Alert that is as OK, below my script:

@section Scripts{
    <script src="~/Scripts/bootbox.min.js"></script>
    <script>
    $(document).ready(function () {
        $.getJSON('@Url.Action("Ajax_Teste")', function (response) {
            alert("getJson sucesso");
        }).fail(function (data) {
            bootbox.alert("Não foi possível processar a sua requisição. abra o log para consulta" + data.responseJSON.msg);
        });
    });
    </script>
}

2 answers

1


Follow the example:

$(document).ready(function() {
  bootbox.alert({
    message: "Não foi possível processar a sua requisição. abra o log para consulta",
    buttons: {
        ok: {
            label: 'Enviar o relatório de Erro.',
            // Se quiser mudar a classe tbm
            className: 'btn-danger'
        },
    },
    callback: function(){
        //seu código aqui
        console.log('clicou');
    }

   }) 
});
@import 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css';
@import 'https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js';
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.js"></script>

Example with confirmation:

$(document).ready(function() {
  bootbox.confirm({
    message: "Não foi possível processar a sua requisição. abra o log para consulta",
    buttons: {
        confirm: {
            label: 'Enviar o relatório de Erro.',
            // Se quiser mudar a classe tbm
            className: 'btn-success',
        },
        cancel: {
            label: 'Não enviar',
            // Se quiser mudar a classe tbm
            className: 'btn-danger',
        }
    },
    callback: function(result){
        //seu código aqui
        if(result)        
          console.log("confirmou");
        else
          console.log("cancelou");
    }

   }) 
});
@import 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css';
@import 'https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js';
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.js"></script>

  • Actually Leandro the ok button will become SEND ERROR REPORT, in which it will capture my error log and send to my email. And when I used this example then Alert is no longer being shown!!!

  • so you need a callback, I would recommend changing Alert to confirm or prompt... so the user has the option to submit the report or simply close. Note: if the user will always send the report, you do not need to do this second post in the client... just send in the action that returns the error.

  • As I do not understand very well, could give an answer showing how to do by prompt, and yes, always the user will send to email!

  • But if you always want to receive the report, if it has not captured anything that is on the user screen, it makes no sense to give this action/option to it. As I said, send the report in the backend, after all you already captured the error and here would just be showing to the user.

  • In this situation, man, there’s always gonna be something captured. That’s why I need to do this, because you’re only in that condition if you have something captured, you understand? Show me inside my context what this prompt would look like, because I never did it!

  • I added the confirm, but I say captured from the DOM being displayed... pq the error message you show comes from the server

  • Leandro, worked perfectly now I did not understand what to do with callback, there I must enter the SMTP settings for sending to the email???

  • No, you cannot send emails by javascript, you will have to create an Action in your controller, make a post for it and send by Asp.net... and now you will understand why from the other question I said you should send the error at the time of capture... : P

Show 3 more comments

1

There are good examples in the documentation: http://bootboxjs.com/documentation.html

For your case, just set buttons:

bootbox.alert({
    message: "Não foi possível processar a sua requisição. abra o log para consulta" + data.responseJSON.msg",
    buttons: {
        ok: {
            label: 'Label do botão OK',
            className: 'btn-success'
        }
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.