CRM-15151 - Ensure form errors always close when popup form submitted
authorColeman Watts <coleman@civicrm.org>
Wed, 20 Aug 2014 10:03:39 +0000 (11:03 +0100)
committerColeman Watts <coleman@civicrm.org>
Wed, 20 Aug 2014 10:03:39 +0000 (11:03 +0100)
js/crm.ajax.js

index 7fc5ea43af62e7f9d0d0be52fa1a6275117bae1a..91dbc43823c1a5fc872af2e9a40d9e814a26cdaf 100644 (file)
     return $(settings.target);
   };
   CRM.loadForm = function(url, options) {
-    var settings = {
+    var formErrors = [], settings = {
       crmForm: {
         ajaxForm: {},
         autoClose: true,
             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));
               });
             }
           }
           }
         },
         beforeSubmit: function(submission) {
+          $.each(formErrors, function() {
+            this && this.close && this.close();
+          });
           $el.crmSnippet('option', 'block') && $el.block();
           $el.trigger('crmFormSubmit', submission);
         }