It would be useful if CCK could understand which fields are not filled (no content inserted), in case someone would like to hide or ignore those empty fields in the final node output (see this thread to know more: http://drupal.org/node/45482 )

This might be already possible with some hack, but would be easier if for "select lists" could be possible to specify a tag (for example:
) to be pasted in the first row of the "Allowed values" field, that the system recognizes as "empty".

Sorry for the not so technical explanation....no coder no motherlanguage... ;-\

thx

CommentFileSizeAuthor
#7 field.tpl.php.txt657 bytesashtonium

Comments

RayZ’s picture

Didn't realize this was a general CCK issue. If so, I believe I would call it a bug. Here's my description of the same issue, specifically for the date field http://drupal.org/node/72085.

marcoBauli’s picture

Title: Recognizing empty fields » Recognizing empty (NULL) fields
solipsist’s picture

This is clearly a bug, empty fields contain:

<br><br class="clear">

So knowing that, you can find a way around it.

bluecobalt’s picture

Has any progress been made in regards to this problem?

marcoBauli’s picture

Title: Recognizing empty (NULL) fields » Recognizing empty fields

yes, the code below will print a field only if it has a value (if is not empty):

 foreach ((array)$field_ticker_id as $item) { 
if(!empty($item['view'])){
echo "<h3 class=\"ticker\">Ticker Id</h3>"; print $item['view'];
} 
} 

this is an example for a cck field called "ticker_id" (thanks Brakkar ;). It is intended to be used in the content-type phptemplate file.

Reverting title since "empty" and "NULL" do not mean the same thing (read more here about this).
Can it be considered fixed at this point, or is not properly a CCK solution?

marcoBauli’s picture

Title: Recognizing empty fields » Do not output empty fields
Category: feature » support
Status: Active » Fixed

maybe was more a support request, to be considered fixed now ;)

ashtonium’s picture

Status: Fixed » Needs work
StatusFileSize
new657 bytes

I'm setting this as a bug, though it may be related to the bug about the content module not storing NULL values: http://drupal.org/node/85929

marcob: your code only hides empty fields if the input type is plain text. If there is any filtering going on, the empty field value gets modified to: <br />\n<br clear="all" /> and is still displayed.

At the moment, in order to universally hide blank fields, you can use this code as your field.tpl.php file: (file is also attatched to this post)

<?php 
$disp = false;
/* temporary fix to hide empty fields:
 * only display the field if any of the items don't match the empty value conditions */
foreach ($items as $item) {
  if(!empty($item['view']) && $item['view'] != "<br />\n<br class=\"clear\" />") { 
    $disp = true;
  }
}
if ($disp): ?>
	<div class="field field-type-<?php print strtr($field_type, '_', '-') ?> field-<?php print strtr($field_name, '_', '-') ?>">
		<h3 class="field-label"><?php print $label ?></h3>
		<div class="field-items">
			<?php foreach ($items as $item) { ?>
				<div class="field-item"><?php print $item['view'] ?></div>
			<?php } ?>
		</div>
	</div>
<?php endif; ?>

This still won't hide empty number fields since those are apparently stored in the database as a 0 rather than a NULL value, and hiding a 0 would also hide entered values of 0 along with the empty fields.

I've marked this as Code Needs Work because I'm sure there's a better way of doing it, and also also because it is just a temporary fix until the storing NULL values bug gets fixed.

karens’s picture

Status: Needs work » Closed (won't fix)

The break in empty fields is actually coming from your filters. For instance, if you have image_asst enabled, empty fields will get <br class="clear"> added to them, but that will disappear if you turn off image_asst. Most of the time I get at least a <br /> in an empty filtered field no matter what filters I am using.

The workaround mentioned here (testing for '<br />' or whatever the filters you have installed do to empty text) is the only way you can handle it. CCK is actually doing what it ought to do, allowing the filters to process the text and there's no way around that when you're using 'filtered text'.

spiffyd’s picture

Version: 4.7.x-1.x-dev » 6.x-2.0-rc9
Priority: Normal » Critical
Status: Closed (won't fix) » Active

Not sure if this is a related issue so I won't start a new thread...

Basically, empty HTML containers for empty CCK Image fields are being outputted when used with Views. Is there any way to hide these empty containers (via CSS) or prevent the code from showing up?

Thanks!

yched’s picture

Priority: Critical » Normal
Status: Active » Closed (won't fix)

Please open a separate issue, describing your exact issue.
Following up on a 2-year-old closed issue is not a good idea.