简体   繁体   中英

stackable popup bootstrap modal close issue

I'd like to display Stackable Modal in my view :

Principal view

.....some code
  @*Pop Up ajout demande*@
                <div class="modal   fade" tabindex="-1" data-focus-on="input:first" role="dialog" id="addModal" style="height: 100%">
                    <div class="modal-dialog" style="width: 100%">
                        <div class="modal-content" style="width: 100%">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <label class="modal-title center-block" style="color:red; font-size:larger"></label>
                            </div>
                            <div class="modal-body">
                                @Html.Partial("AjouterDemandePopUp")

                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal" id="btnEscape">Quitter</button>
                            </div>
                        </div>
                    </div>
                </div>

Partial view AjouterDemandePopUp

...........some code
      <div class="modal " tabindex="-2"   id="VehModal">
                                    <div class="modal-dialog" style="width: 100%">
                                        <div class="modal-content" style="width: 100%">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                <label class="modal-title center-block" style="color:red; font-size:larger">Choix de véhicule</label>
                                            </div>
                                            <div class="modal-body">
                                                <p><label id="labchauffeurs">Chauffeurs disponibles</label> <select id="lstchauffeurs" name="lstchauffeurs" style="width:250px;  "></select>  </p>
                                                <p>
                                                    <table id="tblauto" class="table table-bordered table-striped">
                                                        <thead>
                                                            <tr style="color:white;background-color:#3c8dbc" id="autoheader">

                                                                <th></th>
                                                                <th>Chauffeur</th>
                                                                <th>Marque</th>
                                                                <th>Plaque d’immatriculation</th>
                                                                <th>Kilométrage</th>
                                                                <th>Année de fabrication</th>
                                                                <th>Carte de carburant </th>
                                                                <th>Observation</th>

                                                            </tr>
                                                        </thead>
                                                        <tbody id="tblautoBody"></tbody>

                                                    </table>
                                                </p>

                                               </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-primary" data-dismiss="modal" id="btnSetVehicle">Valider</button>
                                                <button type="button" class="btn btn-default" data-dismiss="modal" id="btnQuit">Annuler</button>
                                            </div>
                                        </div><!-- /.modal-content -->
                                    </div><!-- /.modal-dialog -->
                                </div>

The problem is when I validate or close the second pop ( pop up inside partial view) the first pop up will be closed !!!

I need to know the reasons of this behavior? How can I fix this?

When you click on the button with attribute data-dismiss="modal" then it will call bootstrap function to close all opened modals.

Instead of using built-in function - create your own function, which will close specific modal. Use attribute like data-dismiss-modal="#modal_id" - then you will dismiss modal only with id #modal_id

$(document).on('click', '[data-dismiss-modal]', function () {
    var target = $(this).attr('data-dismiss-modal');
    $(target).modal('hide');
});

Example: https://jsfiddle.net/73mdx4jm/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM