From 3339674f61530ba9247d7aba4654549fd436f2d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= Date: Tue, 29 Oct 2019 09:47:44 +0100 Subject: [PATCH] dialog: add data-autoclose-dialog option (#37253) --- gadjo/static/js/gadjo.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gadjo/static/js/gadjo.js b/gadjo/static/js/gadjo.js index db6c5c0..7d63b3e 100644 --- a/gadjo/static/js/gadjo.js +++ b/gadjo/static/js/gadjo.js @@ -47,6 +47,9 @@ var gadjo_js = gadjo_js || {}; * attribute, a gadjo:dialog-done event is triggered on success, a * gadjo:dialog-submit-error event is triggered on failure. * + * Set data-autoclose-dialog="true" to close the dialog box after the + * submit. + * * Dialog is modal by default, set data-modal="false" for non-modal * dialogs. */ @@ -55,6 +58,7 @@ var gadjo_js = gadjo_js || {}; var selector = $anchor.data('selector') || 'form:not(.gadjo-popup-ignore)'; var title_selector = $anchor.data('title-selector') || '#appbar h2'; var inplace_submit = $anchor.data('inplace-submit'); + var autoclose_dialog = $anchor.data('autoclose-dialog'); var modal = $anchor.data('modal'); if (url == '#') { return false; @@ -217,6 +221,15 @@ var gadjo_js = gadjo_js || {}; } else { $elem.click(); } + var validated = true; + $form.find('input, textarea').each(function() { + if ($(this)[0].checkValidity != undefined) { + validated &= $(this)[0].checkValidity(); + } + }) + if (autoclose_dialog & validated) { + $content.dialog('destroy'); + } } return false; };