Any chance of modifying this module so that empty rows wouldn't output?

I'm using this to enter a list of standard ingredients (left column of labels pre-entered), but in some cases an item might not have an ingredient so the user would remove the label leaving an empty row. I'd like to stop these rows from outputting.

CommentFileSizeAuthor
#1 tablefield_empty.patch668 bytesJacobSingh

Comments

JacobSingh’s picture

Status: Active » Needs review
StatusFileSize
new668 bytes

Here's a patch which hides the table if there are no rows.

jpoesen’s picture

#1 might work to hide an empty table but won't hide empty rows as requested.

Though jQuery is not an ideal solution for everyone, but I'm using it as a basis for specific changes in specific circumstances.

Here's a generic starting point: remove all empty rows in all tables generated by tablefield:

(function ($) {
  // Hide empty rows generated by tablefield
  Drupal.behaviors.afro_tablefield_cleanup = {
    attach: function(context, settings) {
      $('table.tablefield tr').each(function(){
        if($(this).children('td:empty').length === $(this).children('td').length){
          $(this).remove();
        }
      });
    }
  };
})(jQuery);
l1reynolds’s picture

Status: Needs review » Closed (works as designed)

That is fine for now, thanks.

hottaco’s picture

Issue summary: View changes

The script works great, slight modification to keep the table header.

Drupal.behaviors.afro_tablefield_cleanup = {
    attach: function(context, settings) {
      $('table.tablefield > tbody tr').each(function(){
        if($(this).children('td:empty').length === $(this).children('td').length){
          $(this).remove();
        }
      });
    }
  };