After alert open modal

-1

I am trying to make the alert open the modal, but it is not working. In the function I check if the nnfe field is populated.

  function TransferenciaPedido() {
if ($("nnfe").val() == undefined) {
    alert("Preencha o número da NF-e corretamente.");
    $('#myModalNFe').modal('show');
}
else {

}}

I've also tried to put return false; , however, modal does.

I call the function in a button within the modal:

 <button type="button" class="btn btn-success" onclick="TransferenciaPedido();" data-dismiss="modal">Concluir</button>
    
asked by anonymous 13.09.2018 / 15:35

1 answer

-1

Leaving the answer here, for future query cases.

The error is in trying to display the modal with it still open. When you call the function the modal has not yet closed, so it ends up conflicting. The resolution would be:

function TransferenciaPedido() {
    if ($(".nnfe").val() === undefined) {
        alert("Preencha o número da NF-e corretamente.");
    } else {
        $('#myModalNFe').modal('hide');
    }
}

Html

<button type="button" class="btn btn-success" onclick="TransferenciaPedido();">Concluir</button>
    
13.09.2018 / 16:28