Index: flexifield-cck-overrides.inc
===================================================================
RCS file: /home/cvs/edgov_redesign/www_2_0_7/sites/all/modules/flexifield/flexifield-cck-overrides.inc,v
retrieving revision 1.2
diff -u -b -B -r1.2 flexifield-cck-overrides.inc
--- flexifield-cck-overrides.inc	14 Sep 2010 14:25:31 -0000	1.2
+++ flexifield-cck-overrides.inc	23 Sep 2010 15:02:07 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: flexifield-cck-overrides.inc,v 1.2 2010/09/14 14:25:31 jcheek Exp $
+// $Id: flexifield-cck-overides.inc $
 
 /**
  * @file
@@ -84,6 +84,7 @@
       t('Order'),
     );
     $rows = array();
+    $firstEmpty = FALSE; // jwc edgov-177
 
     // Sort items according to '_weight' (needed when the form comes back after
     // preview or failed validation)
@@ -88,11 +89,22 @@
     // Sort items according to '_weight' (needed when the form comes back after
     // preview or failed validation)
     $items = array();
+
     foreach (element_children($element) as $key) {
+
       if ($key !== $element['#field_name'] .'_add_more') {
+
+        $empty = flexifield_content_is_empty($element[$key], '');
+
+        if (!$empty || !$firstEmpty)
         $items[] = &$element[$key];
+
+        $firstEmpty |= $empty;
+
       }
+
     }
+
     usort($items, '_content_sort_items_value_helper');
 
     // Add the items as table rows.
Index: flexifield-widget.inc
===================================================================
RCS file: /home/cvs/edgov_redesign/www_2_0_7/sites/all/modules/flexifield/flexifield-widget.inc,v
retrieving revision 1.2
diff -u -b -B -r1.2 flexifield-widget.inc
--- flexifield-widget.inc	14 Sep 2010 14:25:31 -0000	1.2
+++ flexifield-widget.inc	23 Sep 2010 15:02:07 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: flexifield-widget.inc,v 1.2 2010/09/14 14:25:31 jcheek Exp $
+// $Id: flexifield-widget.inc $
 
 /**
  * @file
@@ -249,6 +249,11 @@
   // adding another item (with a small modification).
   if (!count($aParents) || (count($aParents) == 1 && module_exists('fieldgroup') && ($aParents[0] == _fieldgroup_field_get_group(str_replace('-', '_', $sTypeNameUrl), $sFieldName)))) {
     module_load_include('inc', 'flexifield', 'flexifield-cck-overrides');
+
+// jwc edgov-177
+    global $JWC_IAmAddingANewFieldSoGiveMeABrokenIsEmptyFunction;
+    $JWC_IAmAddingANewFieldSoGiveMeABrokenIsEmptyFunction = TRUE;
+
     return flexifield_add_more_js($sTypeNameUrl, $sFieldName);
   }
   
Index: flexifield.module
===================================================================
RCS file: /home/cvs/edgov_redesign/www_2_0_7/sites/all/modules/flexifield/flexifield.module,v
retrieving revision 1.2
diff -u -b -B -r1.2 flexifield.module
--- flexifield.module	14 Sep 2010 14:25:31 -0000	1.2
+++ flexifield.module	23 Sep 2010 15:02:07 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: flexifield.module,v 1.2 2010/09/14 14:25:31 jcheek Exp $
+// $Id: flexifield.module,v 1.1.2.13 2010/04/11 20:44:35 effulgentsia Exp $
 
 /**
  * @file
@@ -380,6 +380,9 @@
   // CCK doesn't remove it from the db. This needs more investigation, but is not a bug with 
   // this module.
   
+// jwc edgov-177
+  global $JWC_IAmAddingANewFieldSoGiveMeABrokenIsEmptyFunction;
+
   // If no content type is specified, or if it's not a valid type, treat the item as empty.
   $sItemType = $aItem['type'];
   if (!$sItemType) {
@@ -391,7 +395,13 @@
   }
   
   // If the content type has no fields, treat the item as not empty.
-  if (!count($aContentTypeInfo['fields'])) {
+  // jwc This is necessary for "Add another item" but messes up standard
+  // form rendering.  So only use if we are adding another item.
+
+  if (!count($aContentTypeInfo['fields']) &&
+    $JWC_IAmAddingANewFieldSoGiveMeABrokenIsEmptyFunction) {
+    $JWC_IAmAddingANewFieldSoGiveMeABrokenIsEmptyFunction = FALSE;
+// only let one be shown
     return FALSE;
   }
   
@@ -404,16 +414,69 @@
   // If the item value isn't literally empty, check to see if any field is not empty by its own standards
   // of what that means.
   $bEmpty = TRUE;
+
   foreach ($aValue as $sChildFieldName => $aChildFieldItems) {
     $aChildFieldSettings = $aContentTypeInfo['fields'][$sChildFieldName];
+
     if (is_array($aChildFieldSettings) && is_array($aChildFieldItems)) {
+// if it has ChildFieldSettings[] and ChildFieldItems[]
+
       foreach ($aChildFieldItems as $aChildFieldItem) {
-        if (is_array($aChildFieldItem) && !module_invoke($aChildFieldSettings['module'], 'content_is_empty', $aChildFieldItem, $aChildFieldSettings)) {
+
+        if (is_array($aChildFieldItem) &&
+          !module_invoke($aChildFieldSettings['module'],
+          'content_is_empty', $aChildFieldItem, $aChildFieldSettings)) {
+
           $bEmpty = FALSE;
           break;
+
+        } // if module_invoke says it's empty
+
+      } // for each child item
+
+    } elseif (is_array($aChildFieldItems)) {
+// else if it only has ChildFieldItems[]
+
+      foreach ($aChildFieldItems as $aChildFieldKey => $aChildFieldItem) {
+
+        if (substr($aChildFieldKey, 0, 6) == 'field_') {
+// check all content fields
+
+          if (is_array($aChildFieldItem)) {
+
+            if (is_array($aChildFieldItem[0])) {
+
+              if (is_array($aChildFieldItem[0]['value'])) {
+// Some Add another items are like this - NOP
+
+              } else { // [0][value] not an array
+
+                if (($aChildFieldItem[0]['value'] != '') &&
+                  (substr($aChildFieldItem[0]['value'], 0, 4) != '0010') &&
+                  (substr($aChildFieldItem[0]['value'], 0, 10) != '2010-00-00') &&
+                  ($aChildFieldItem[0]['value'] != '2010-01-01T00:00:00') &&
+                  ($aChildFieldItem[0]['value'] != '2010-01-01 00:00:00')) {
+
+                  return FALSE;
+
         }
+
+                if (($aChildFieldItem[0]['url'] != '')) {
+                  return FALSE;
       }
-    }
+
+              } // is ChildFieldItem[0][value] an array?
+
+            } // is ChildFieldItem[0] an array?
+
+          } // is ChildFieldItem an array?
+
+        } // only process if it's a content field
+
+      } // loop through each child
+
+    } // if it has ChildFieldSettings[] and ChildFieldItems[] or not
+
     if (!$bEmpty) {
       break;
     }
