From 77ae6c17e718669edcae8898792e20be3db18053 Mon Sep 17 00:00:00 2001 From: pravdomil Date: Tue, 19 Jun 2018 16:35:06 +0200 Subject: submit inline form on click outside --- client/lib/inlinedform.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/lib/inlinedform.js b/client/lib/inlinedform.js index 56768a13..c652c646 100644 --- a/client/lib/inlinedform.js +++ b/client/lib/inlinedform.js @@ -75,6 +75,16 @@ InlinedForm = BlazeComponent.extendComponent({ EscapeActions.register('inlinedForm', () => { currentlyOpenedForm.get().close(); }, () => { return currentlyOpenedForm.get() !== null; }, { - noClickEscapeOn: '.js-inlined-form', + enabledOnClick: false } ); + +// submit on click outside +document.addEventListener("click", function(evt) { + const formIsOpen = currentlyOpenedForm.get() && currentlyOpenedForm.get().isOpen.get(); + const isClickOutside = $(evt.target).closest(".js-inlined-form").length === 0; + if (formIsOpen && isClickOutside) { + $('.js-inlined-form button[type=submit]').click(); + currentlyOpenedForm.get().close(); + } +}, true); -- cgit v1.2.3-1-g7c22 From 620bbb3394bdfabeb63eb7a43f822b37da7ceab5 Mon Sep 17 00:00:00 2001 From: pravdomil Date: Tue, 19 Jun 2018 16:41:27 +0200 Subject: refactor --- client/lib/inlinedform.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/lib/inlinedform.js b/client/lib/inlinedform.js index c652c646..272d79f7 100644 --- a/client/lib/inlinedform.js +++ b/client/lib/inlinedform.js @@ -81,10 +81,10 @@ EscapeActions.register('inlinedForm', // submit on click outside document.addEventListener("click", function(evt) { - const formIsOpen = currentlyOpenedForm.get() && currentlyOpenedForm.get().isOpen.get(); + const openedForm = currentlyOpenedForm.get() const isClickOutside = $(evt.target).closest(".js-inlined-form").length === 0; - if (formIsOpen && isClickOutside) { + if (openedForm && isClickOutside) { $('.js-inlined-form button[type=submit]').click(); - currentlyOpenedForm.get().close(); + openedForm.close(); } }, true); -- cgit v1.2.3-1-g7c22