From 5c62258c60a473ab44e2567c655ed42074ff9b9c Mon Sep 17 00:00:00 2001
From: Renato Vasconcellos <revagomes@gmail.com>
Date: Tue, 28 Oct 2014 20:04:52 +0000
Subject: [PATCH] Issue #2365073 by revagomes, lhguerra: Fixed form validation
 issues when multiple ajaxified forms in the same page.

---
 ajax_form_entity.module |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/ajax_form_entity.module b/ajax_form_entity.module
index b8c7765..3a6a6d7 100644
--- a/ajax_form_entity.module
+++ b/ajax_form_entity.module
@@ -184,12 +184,17 @@ function ajax_form_entity_form_alter(&$form, $form_state) {
  */
 function ajax_form_entity_callback($form, $form_state) {
   $commands = array();
+
+  // Remove old potential errors and also removes the error classes in case if
+  // there is more than one ajaxified form in the same page.
+  $commands[] = ajax_command_invoke('input', 'removeClass', array('error'));
+  $commands[] = ajax_command_invoke('select', 'removeClass', array('error'));
+  $commands[] = ajax_command_invoke('textarea', 'removeClass', array('error'));
+  $commands[] = ajax_command_invoke('.form-checkboxes', 'removeClass', array('error'));
+  $commands[] = ajax_command_invoke('.form-radios', 'removeClass', array('error'));
+
   // Return just error messages if there is an error.
   if ($errors = form_get_errors()) {
-    // Remove old potential errors.
-    $commands[] = ajax_command_invoke('input', 'removeClass', array('error'));
-    $commands[] = ajax_command_invoke('select', 'removeClass', array('error'));
-    $commands[] = ajax_command_invoke('textarea', 'removeClass', array('error'));
     // Change classes of the forms to display them as error.
     // In  case of multiple form, IDs have numbers added (like page-node-form--2).
     $form_number = '';
-- 
1.7.9.5

