From: Coleman Watts Date: Wed, 20 Aug 2014 10:03:39 +0000 (+0100) Subject: CRM-15151 - Ensure form errors always close when popup form submitted X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=55cb6db19e6dfda32b4488e983e8bfc11b6111b5;p=civicrm-core.git CRM-15151 - Ensure form errors always close when popup form submitted --- 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); }