Prompt a warning message before closing a modal

一曲冷凌霜 提交于 2019-12-11 11:08:44

问题


I have a modal and i closing the dialog on clicking outside the modal dialog using backdrop property . I have a form in modal. If any changes are made in form and click outside the modal i should warn the user about unsaved changes. The code i am using

  $(window).on('hide.bs.modal', function() { 
       var changed_data = $("#formid").serialize();
                if(changed_data!=original_data)
                {
                    var result = confirm("Are you sure ?");
                    if(result == true){
                       $('#dialog').data('bs.modal').options.backdrop = true;
                    }
                    else
                    {
                      $('#dialog').data('bs.modal').options.backdrop = "static";
                    }
                }
                else
                {
                    $('#dialog').data('bs.modal').options.backdrop = true;
                }
            });

If i click outside the dialog the above function is calling and backdrop option value is changing but the changes are reflecting in the next call of dialog(again if i open the dialog).

来源:https://stackoverflow.com/questions/29027047/prompt-a-warning-message-before-closing-a-modal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!