0
I have a div
bootstrap modal that sits on the "masterpage" _Layout.csthml
.
<div id="ModalAlteracao" class="modal fade">
<div class="modal-dialog">
<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 id="TituloModalAlteracao" class="modal-title">Atenção</h4>
</div>
<div class="modal-body">
<p>
Houve alteração de dados nesta tela, as demais informações das telas seguintes serão apagadas.
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancelar</button>
<button id="btnConfirmarAlteracao" type="button" class="btn btn-primary">Salvar</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
I created a function that is called in several different Views, to open this modal, and when clicking the Save button, run a javascript function passed by parameter.
function confirmarAlteracao(callback) {
$("#btnConfirmarAlteracao").click(function () {
callback();
$('#ModalAlteracao').modal('hide');
});
$('#ModalAlteracao').modal('show');
}
Call example of this function:
function salvarPlaca() {
if (!houveAlteracaoPlaca()) {
efetivarAlteracaoPlaca();
}
else {
// exibe o dialog de confirmação, e passa a função de callback caso o usuário clique em "sim"
confirmarAlteracao(efetivarAlteracaoPlaca);
}
}
The problem is that if user click Cancel, and then click again on the button that runs salvarPlaca
, and this second time confirm, the function efetivarAlteracaoPlaca
is being executed twice.
Thanks.This solution worked out! If you are going to post the others, and it works out I accept the answer. But for now this met in a simple way!
– user26552