Prompt a warning message before closing a modal
Asked Answered
C

0

1

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).

Catenoid answered 13/3, 2015 at 7:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.