The "Hide empty fields" option for fields row style is much appreciated, but in both 2.8 and current dev it does not seem to be working for me, unless I'm missing something very basic here. In both single- and multiple-value fields, the label is displayed whether or not I have this option checked. This is true even for simple text fields.

Is this option working for anyone in Views 2?

CommentFileSizeAuthor
#3 view-empty-fields-test.txt4.72 KBdafeder

Comments

merlinofchaos’s picture

Status: Active » Postponed (maintainer needs more info)

Check the HTML. Is CCK putting HTML in there despite there being no actual value? If so, Views cannot distinguish between this non-printing HTML and no value. In that case, it would be a CCK issue.

dafeder’s picture

Thanks Merlin. No, there doesn't appear to be any html in there. In the source, there's nothing after the tag and in devel both [raw] and [content] for those fields come up as 0 characters.

dafeder’s picture

StatusFileSize
new4.72 KB

Here is the export of a view on a test install of drupal, using the Garland theme, where I get labels on both empty CCK text fields and an empty node body.

svetlin’s picture

I had the same problem. When I deleted all markup from the field template, the label was hidden.

merlinofchaos’s picture

svetlin's comment in #4 is consistent with what I said in #1.

Can you paste some actual HTML (be sure to use <code> tags so the HTML doesn't get corrupted) output where the empty field is being displayed?

dafeder’s picture

Thanks - I want ahead and just used the old theme method of hiding the field labels for empty fields... but so we can put this to rest, here's the html from one of my test views where fields are showing. This is the html from two nodes, one has content in its fields, one doesn't except for the title.

      <div class="view-content">
      <div class="item-list">
    <ul>
          <li class="views-row views-row-1 views-row-odd views-row-first">  
  <div class="views-field-title">
          <label class="views-label-title">
        Title:
      </label>
                <span class="field-content"><a href="/node/4">Whatever</a></span>

  </div>
  
  <div class="views-field-field-options-value">
          <label class="views-label-field-options-value">
        Options:
      </label>
                <div class="field-content"><div class="field-item field-item-0">Option 1</div><div class="field-item field-item-1">Option 3</div></div>
  </div>
  
  <div class="views-field-field-texttest-value">

          <label class="views-label-field-texttest-value">
        textfield:
      </label>
                <span class="field-content">ergererger</span>
  </div>
  
  <div class="views-field-body">
          <label class="views-label-body">
        Body:
      </label>

                <div class="field-content"><p>dgnfg</p></div>
  </div>
</li>
          <li class="views-row views-row-2 views-row-even views-row-last">  
  <div class="views-field-title">
          <label class="views-label-title">
        Title:
      </label>
                <span class="field-content"><a href="/node/5">zxczcx</a></span>

  </div>
  
  <div class="views-field-field-options-value">
          <label class="views-label-field-options-value">
        Options:
      </label>
                <div class="field-content"></div>
  </div>
  
  <div class="views-field-field-texttest-value">
          <label class="views-label-field-texttest-value">

        textfield:
      </label>
                <span class="field-content"></span>
  </div>
  
  <div class="views-field-body">
          <label class="views-label-body">
        Body:
      </label>
                <div class="field-content"></div>
  </div>

</li>
      </ul>
</div>    </div>
  
  
merlinofchaos’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

So here's the thing:

<div class="field-content"></div>

That's markup provided by CCK that is making Views think the field is not empty. Which is what I thought in #1. I can't do anything about that.

dafeder’s picture

But, the only place anywhere in drupal where "field-content" is produced is in views, in the default views-view-fields.tpl.php. If you disable CCK, the body field is still wrapped in the field-content div.

elandirayan’s picture

Hai Defeder,

One tric to Hide the field. I tried lot with views and done one tricky work. What i done is in the row stryle template, i add the striptags and replaced. It is working fine.

Please find the sample in my row style template file:

foreach ($fields as $id => $field):
if (!empty($field->separator)):
print $field->separator;
endif;
$elan = strlen(strip_tags($field->content));
if ($elan > 1):
if ($field->label):

print $field->label;
print $field->content;

endif;
endif;
endforeach;

prabhakarsun’s picture

For me, adding a filter of the field worked. i.e. if you are getting a blank imagefield [ex. product photo], add imagefield true filter. [ex. product photo - true].

Kasha Linka’s picture

Adding the filter suggested in #10 worked for me, too. Seems that simply setting up the field and row style settings to not display the field if it's empty weren't enough. The filter was also needed. Thanks very much for this thread.

AlanAtLarge’s picture

Subscribing

itserich’s picture

subscribing

anrikun’s picture

Shouldn't this be opened again because of #8?
I'm having the same issue.
So far, the only way to hide empty fields seems to be to check "Hide if empty" at field level, one by one(!)
Checking "Hide empty fields" as row level has absolutely no effect.

aspacepig’s picture

Status: Closed (won't fix) » Active

Thanks Manoj! #10 worked like a charm. Drupal gets a lot more fun once one starts to get the hang of views.

iamjon’s picture

Status: Active » Closed (works as designed)

I'm marking this as closed.
I'm quite sure the mark up is coming from cck in the text formatter.