1
I’m trying to recreate the javascript native confirm component and came across a question.
Example:
if (confirm("meu texto vai aqui")) { // Aguarda retorno {true ou false}
console.log("faça algo aqui");
}
By default, as long as the user does not click OK or Cancel it will not return to the if stream. in this case I am trying to play it.
Example:
function msgConfirm(texto) {
var resposta = $(".resposta");
resposta.empty();
var modal =
"<div class='modal fade msgConfirm' tabindex='-1' role='dialog'>" +
" <div class='modal-dialog modal-sm' >" +
" <div class='modal-content' >" +
" <div class='modal-header' >" +
" <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'> × </span></button >" +
" <h4 class='modal-title' id='msgConfirmTitle'> </h4>" +
" </div>" +
" <div class='modal-body'>" +
" <p id='msgConfirmContent' > </p>" +
" </div>" +
" <div class='modal-footer' >" +
" <button type='button' class='btn btn-primary' id='msgConfirmConfirm' > Ok </button>" +
" <button type='button' class='btn btn-default' data-dismiss='modal' id='msgConfirmCancel' > Cancelar </button>" +
" </div>" +
" </div>" +
" </div>" +
"</div>";
resposta.append(modal);
resposta.find("#msgConfirmContent").html(texto);
resposta.find(".msgConfirm").modal("show");
$("#msgConfirmConfirm").click(function() {
return true;
});
}
And the moment I call it the return is given, without intervention of the event listener click.
if (msgConfirm("meu texto vai aqui")) { // Retorno imediato {undefined}
console.log("faça algo aqui");
}
So what I need to know and, how can I reproduce the behavior of confirm?
I couldn’t understand what you meant...
– LocalHost