From 55cb6db19e6dfda32b4488e983e8bfc11b6111b5 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 20 Aug 2014 11:03:39 +0100 Subject: [PATCH] CRM-15151 - Ensure form errors always close when popup form submitted --- js/crm.ajax.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/js/crm.ajax.js b/js/crm.ajax.js index 7fc5ea43af..91dbc43823 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -333,7 +333,7 @@ return $(settings.target); }; CRM.loadForm = function(url, options) { - var settings = { + var formErrors = [], settings = { crmForm: { ajaxForm: {}, autoClose: true, @@ -423,9 +423,10 @@ response.url = data.url; $el.html(response.content).trigger('crmLoad', response).trigger('crmFormLoad', response); if (response.status === 'form_error') { + formErrors = []; $el.trigger('crmFormError', response); $.each(response.errors || [], function(formElement, msg) { - $('[name="'+formElement+'"]', $el).crmError(msg); + formErrors.push($('[name="'+formElement+'"]', $el).crmError(msg)); }); } } @@ -438,6 +439,9 @@ } }, beforeSubmit: function(submission) { + $.each(formErrors, function() { + this && this.close && this.close(); + }); $el.crmSnippet('option', 'block') && $el.block(); $el.trigger('crmFormSubmit', submission); } -- 2.25.1