Do not close modals when clicking on the background if the form has changed
Fixes #5239 Closes #5255
This commit is contained in:
committed by
Frédéric Guillot
parent
e01a361ea4
commit
89821c759e
@@ -1,8 +1,9 @@
|
||||
(function () {
|
||||
var isOpen = false;
|
||||
var isFormDirty = false;
|
||||
|
||||
function onOverlayClick(e) {
|
||||
if (e.target.matches('#modal-overlay')) {
|
||||
if (e.target.matches('#modal-overlay') && isFormDirty === false) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
destroy();
|
||||
@@ -13,6 +14,10 @@
|
||||
KB.trigger('modal.close');
|
||||
}
|
||||
|
||||
function onFormChange() {
|
||||
isFormDirty = true;
|
||||
}
|
||||
|
||||
function onFormSubmit() {
|
||||
KB.trigger('modal.loading');
|
||||
submitForm();
|
||||
@@ -51,6 +56,7 @@
|
||||
function afterRendering() {
|
||||
var formElement = KB.find('#modal-content form');
|
||||
if (formElement) {
|
||||
formElement.on('change', onFormChange, false);
|
||||
formElement.on('submit', onFormSubmit, false);
|
||||
}
|
||||
|
||||
@@ -122,8 +128,9 @@
|
||||
|
||||
function destroy() {
|
||||
isOpen = false;
|
||||
var overlayElement = KB.find('#modal-overlay');
|
||||
isFormDirty = false;
|
||||
|
||||
var overlayElement = KB.find('#modal-overlay');
|
||||
if (overlayElement) {
|
||||
KB.trigger('modal.beforeDestroy');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user