From 1902a58961282340a12f0ac58b2176386edc2ad6 Mon Sep 17 00:00:00 2001
From: Ryan Price <pricester@gmail.com>
Date: Thu, 23 Feb 2012 16:13:05 -0500
Subject: [PATCH] Fixing issue #1452510 (problem with webform_grid types.

---
 webform_conditional.module |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/webform_conditional.module b/webform_conditional.module
index df45bb9..51d11bc 100644
--- a/webform_conditional.module
+++ b/webform_conditional.module
@@ -199,6 +199,14 @@ function webform_conditional_element_after_build($form_element, &$form_state) {
     $components = _webform_conditional_get_all_components($form_element['#webform_component']['nid'], $submitted_values);
     $was_hidden = _webform_conditional_was_hidden($form_element['#webform_component']['cid'], $components);
     if ($was_hidden) {
+      if ($form_element['#type'] == 'webform_grid') {
+          foreach ($form_element as &$element) {
+              //one level of depth is enough, as webform_grid won't go further
+              if (is_array($element) && isset($element['#required'])) {
+                  $element['#required'] = FALSE;
+              }
+          }
+      }
       $form_element['#required'] = FALSE;
       _webform_condtional_clear_element_values($form_element);
     }
@@ -310,6 +318,15 @@ function _webform_condtional_clear_element_values(&$element) {
       $element['day']['#value'] = '';
       $element['year']['#value'] = '';
       break;
+    case 'webform_grid':
+      kpr($element);
+      foreach ($element as &$elem) {
+        //one level of depth is enough, as webform_grid won't go further
+        if (is_array($elem) && array_key_exists('#value', $elem)) {
+            $elem['#value'] = '';
+        }
+      }
+      break;
       //@todo Add other comoponet types that need special clearing logic
   }
 }
@@ -654,7 +671,7 @@ function webform_conditional_webform_submission_render_alter(&$submission) {
  */
 
 function _webform_conditional_hide_submission_elements(&$submission_children, $components) {
-  foreach ($submission_children as $key => &$child) {
+    foreach ($submission_children as $key => &$child) {
     if (element_child($key)) {
       if (_webform_conditional_was_hidden($child['#webform_component']['cid'], $components)) {
         unset($submission_children[$key]);
-- 
1.7.8.msysgit.0

