简体   繁体   English

模式关闭后页面无响应

[英]Page unresponsive after modal close

A have a webapp developed with Spring boot and thymeleaf as front end. A 有一个使用 Spring 引导和 thymeleaf 作为前端开发的 webapp。 We display all the groups available to review.我们显示所有可供审查的组。 Once user clicks a group we list documents in it tabular form and once user clicks on and document we provide its details.一旦用户单击一个组,我们就会以表格的形式列出文档,一旦用户单击并记录我们就会提供其详细信息。 All these I am handling through ajax call and defining on click method.所有这些我都是通过 ajax 调用和定义点击方法来处理的。 Once user gets to detail section they are provided with more details on that document where they can go and modify or add more through modal.一旦用户进入详细信息部分,他们将获得有关该文档的更多详细信息,他们可以在其中 go 并通过模式修改或添加更多信息。 Below is the modal下面是模态

      <!-- Modal start-->
    <div id="editModal" tabindex="-1" class="modal fade" role="dialog">
        <div class="modal-dialog" role="document">
            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <h5 id="pTitle" class="modal-title">Edit</h5>
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                </div>
                <div class="modal-body">
                    <div class="row" id="firstNameRow">
                        <div class="form-group col-sm-12">
                            <label for="firstName" class="col-sm-4">First Name: </label>
                            <input class="col-sm-8" type="text" id="firstName" maxlength="32" onkeydown="return validateInputFields(this,event)"/>
                            <span class="text-danger" style="display:none;float: right;" id="firstNameError">First name is required.</span>
                        </div>
                    </div>
                    <div class="row" id="middleNameRow">
                        <div class="form-group col-sm-12">
                            <label for="middleName" class="col-sm-4">Middle Name: </label>
                            <input  class="col-sm-8" type="text" id="middleName" maxlength="32" onkeydown="return validateInputFields(this,event)"/>
                            <span class="text-danger" style="display:none;float: right;" id="middleNameError"></span>
                        </div>
                    </div>
                    <div class="row has-danger" id="lastNameRow">
                        <div class="form-group col-sm-12">
                            <label for="lastName" class="col-sm-4">Last Name: </label>
                            <input  class="col-sm-8 is-invalid" type="text" id="lastName" maxlength="32" onkeydown="return validateInputFields(this,event)" />
                            <div class="text-danger" style="display:none;float: right;" id="lastNameError" >Last name is required.</div>

                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button"  class="btn btn-primary" th:onclick="'save();'" id="saveButton"  data-backdrop="false" data-keyboard="false">Save</button>
                    <button type="button" class="btn btn-neutral" data-dismiss="modal">Cancel</button>
                </div>
            </div>
        </div>
    </div>
    <!--Modal end-->

And here is my save function:这是我保存的 function:

       function saveParty(){
var hasError = validateParty();
if(!hasError){
    //To close the modal and get back to the previous screen
    document.getElementById("saveButton").setAttribute("data-dismiss","modal");
    var data = loadPartyDetails();
    var objectID = $("#objectID").val();
    $.ajax({
    type : "POST",
    contentType: "application/json",
    url: "/saveDetails/" + objectID + "/",
    data: JSON.stringify(data),
    timeout : 100000,
    success : function(result) {
        $("#detailsPanel").html(result);
        document.getElementById("successMsgParties").style.display="";
        $('#successMsgParties').delay(5000).fadeOut('slow');
    },
    error : function(e) {
        console.log("ERROR: ", e);
    },
    done : function(e) {
        console.log("DONE");
    }
});

}

} }

The call to make modal open:使模态打开的调用:

            <td class="text-center"><a th:id="${iter.index + 1}" onclick="populateModal(this);" class="glyphicon glyphicon-pencil" data-toggle="modal" data-target="#editModal"></a></td>

And all this has been working fine.所有这一切都运行良好。 But sometimes all of sudden the whole page hangs up, I cant scroll I cant click on the links and have to refresh the page to continue.但有时突然整个页面都挂了,我不能滚动我不能点击链接,必须刷新页面才能继续。 There are no errors on the console and have compare the response when the screen freeze and when it doesn't and there is no difference.控制台上没有错误,并且比较了屏幕冻结和没有冻结时的响应,并且没有区别。 At this point I am lost on where to look for and what could be the issue.在这一点上,我迷失了在哪里寻找以及可能是什么问题。 Any directions will be appreciated.任何方向将不胜感激。

Update: So I found that modal-open class was added but not getting remove when the screen froze, so I added below in my javascript.更新:所以我发现添加了 modal-open class 但在屏幕冻结时没有被删除,所以我在下面添加了我的 javascript。 It does unable to page to scroll but all the links on the page are still disabled.它确实无法滚动页面,但页面上的所有链接仍然被禁用。

      $("body").removeClass("modal-open");

Alright, I found one more thing, below div element stays there whenever screen freeze.好吧,我又发现了一件事,只要屏幕冻结,下面的 div 元素就会停留在那里。 How can I found out which div element is this?我怎样才能知道这是哪个 div 元素?

    <div class="modal-backdrop fade show"></div>

Any guidelines on how to close the modal appropriately?关于如何适当关闭模式的任何指南?

Programmatically dismissing a Modal can be done using $('#editModal').modal('hide')可以使用$('#editModal').modal('hide')以编程方式解除 Modal

So either the modal is dismissed using the close or cancel button or from the Javascript using the method I shared.因此,要么使用关闭或取消按钮关闭模式,要么使用我共享的方法从 Javascript 关闭模式。

I noticed that the below div element being added which is making screen freeze.我注意到添加了以下 div 元素,这使屏幕冻结。 I have to hide this through javascript.我必须通过 javascript 隐藏它。

                  <div class="modal-backdrop fade show"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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