Modal does not close, boostrap 4.0

0

Good afternoon.

I have a page in PHP, where there is a div to open a modal.

(div code and button to call modal)

<!-- Modal para adicionar cargos -->
        <div class="modal fade" id="Modal_AddCargos" tabindex="-1" role="dialog" aria-labelledby="Modal_ModalAddCargos" aria-hidden="true">
   <div class="ConteudoModalCargos">

   </div>
</div>

<div 
    class="BotaoFlutuavel ShowTooltip" 
    data-toggle="modal"
    data-placement="left"
    data-target="#Modal_AddCargos"
    title="Cadastrar Novo Cargo">
    <i class="IconePlus">+</i>
</div>

Here is the code to open the modal via ajax.

 // Abrir Modal Cargos
            $('#Modal_AddCargos').on('show.bs.modal', function (e) 
            {
                let IdCargo = $(e.relatedTarget).data('id');

                $.ajax(
                {
                    type: 'POST',
                    url: 'ModalCargo.php',
                    data:
                    {
                        IdCargo: IdCargo
                    }, 
                    success: function (data) 
                    {
                        $('.ConteudoModalCargos').html(data);
                    }
                });
            }); 
        // FIM, $('#Modal_AddCargos').on('show.bs.modal', function (e)

This part of code is all in the same file called Charges.php.

The following is the modal content:

<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header" >
            <h5 class="modal-title" id="TituloModalCargos">Cadastrar Cargos</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <div class="modal-body">
            <form id="FormCargos" name="FormCargos">
                <div class="row">
                    <div class="form-group col-sm">
                        <label for="edtDescricaoCargo" class="FormLabelRequired" >Descrição </label> 
                        <input type="text" id="edtDescricaoCargo" name="edtDescricaoCargo" class="form-control maxlength" maxlength="50" value="<?=$Cargo->getDescricao();?>" placeholder="Digite a descrição" required />
                    </div> <!-- FIM, edtDescricaoCargo -->
                </div> <!-- FIM, row.Descrição -->

                <!-- HIDDEN -->
                <input type="hidden" name="edtIdCargo" id="edtIdCargo" value="<?=$Cargo->getIdCargo();?>"> 
            </form> <!-- FIM, form#FormCargos -->
        </div> <!-- FIM, .modal-body -->

        <div class="modal-footer">
                <a href="#" class="btn btn-default mr-auto" data-dismiss="modal" title= "Cancelar Cadastro" aria-label="close">Cancelar</a>

                <a href="#" id="BtnGravarCargo" class="btn btn-primary" title="Gravar Cargo">Gravar</a>
            </div> <!-- FIM, .row /modal-footer -->
        </div> <!-- FIM, modal-footer -->
    </div> <!-- FIM, modal-content -->
</div> <!-- FIM, .modal-content -->

The problem is that when I click on the "X" to close the modal, or on the cancel button, the modal does not close: / Any tips? Thank you in advance!

    
asked by anonymous 23.07.2018 / 20:10

1 answer

2

People already discovered the answer .. The new Bootstrap, you need to tar the modal-dialog class to be able to close the modal. I've added the "modal-dialog" class in the class where it receives the modal content via ajax. (Class: ContentModal Charges). And I removed it from my modal file, thus became the

Upload file.php:

<!-- Modal para adicionar cargos -->
    <div class="modal fade" id="Modal_AddCargos" tabindex="-1" role="dialog" aria-labelledby="Modal_ModalAddCargos" aria-hidden="true">
        <div class="modal-dialog">

        </div>
    </div>

    <div 
        class="BotaoFlutuavel ShowTooltip" 
        data-toggle="modal"
        data-placement="left"
        data-target="#Modal_AddCargos"
        title="Cadastrar Novo Cargo">
            <i class="IconePlus">+</i>
    </div>

Cargo JS.php:

 $('#Modal_AddCargos').on('show.bs.modal', function (e) 
            {
                let IdCargo = $(e.relatedTarget).data('id');

                $.ajax(
                {
                    type: 'POST',
                    url: 'ModalCargo.php',
                    data:
                    {
                        IdCargo: IdCargo
                    }, 
                    success: function (data) 
                    {
                        $('#Modal_AddCargos .modal-dialog').html(data);
                    }
                });
            });

File where there is the modal content:

<div class="modal-content">
    <div class="modal-header" >
        <h5 class="modal-title" id="TituloModalCargos">Cadastrar Cargos</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    <div class="modal-body">
        <form id="FormCargos" name="FormCargos">
            <div class="row">
                <div class="form-group col-sm">
                    <label for="edtDescricaoCargo" class="FormLabelRequired" >Descrição </label> 
                    <input type="text" id="edtDescricaoCargo" name="edtDescricaoCargo" class="form-control maxlength" maxlength="50" value="<?=$Cargo->getDescricao();?>" placeholder="Digite a descrição" required />
                </div> <!-- FIM, edtDescricaoCargo -->
            </div> <!-- FIM, row.Descrição -->

            <!-- HIDDEN -->
            <input type="hidden" name="edtIdCargo" id="edtIdCargo" value="<?=$Cargo->getIdCargo();?>"> 
        </form> <!-- FIM, form#FormCargos -->
    </div> <!-- FIM, .modal-body -->

    <div class="modal-footer">
        <a href="#" class="btn btn-default mr-auto" data-dismiss="modal" title= "Cancelar Cadastro" aria-label="close">Cancelar</a>

        <a href="#" id="BtnGravarCargo" class="btn btn-primary" title="Gravar Cargo">Gravar</a>
    </div> <!-- FIM, .row /modal-footer -->
</div> <!-- FIM, modal-footer -->

Thanks for this, I have no idea, I've read and reread the boostrap documentation, and it does not say anything about it. If anyone knows anything, they can comment here. Thank you all!

    
23.07.2018 / 20:16