Hi,

I would like to show a certain field in a view only when another field is empty. I'm using profile fields and want to be able to put a check mark in one profile field when another profile field should be excluded from a view. Without that check mark the other profile field should be included in the view. This needs to be validated independently for each user profile.

It seems this type of field validation should be possible with the Views Custom Field module, but I would need help with the code for the validation.

Thanks a lot!

Comments

dawehner’s picture

Project: Views (for Drupal 7) » Views Custom Field
Version: 6.x-2.5 » 6.x-1.x-dev

Views is not a support queue for views custom field.
Move to views custom field . They know the module much better than everything else here.

rpk’s picture

Title: Display field only if another field is empty » Still need help: Display field only if another field is empty
Edward Andrews’s picture

I use code like this to print an email address - the permission tick box is set to store hide or show:


//Get email address
$text = $data -> node_data_field_p2_email;

//Check permissions and print
$perm ="mistake";
$perm = $data -> node_data_field_p2_email_permission_value;

if ($perm == "show") print $text;
elseif ($perm == "hide") print "";
else print "<strong><span class='mistake'>Something's gone wrong</span></strong>";

Hope that's useful.
Edward

rpk’s picture

Hi Edward,

Thanks for the code - I will try to adapt that to my site!

I would still appreciate help from others if they have solved what I'm trying to achieve.

Thanks!

lunk rat’s picture

I need to do the same thing (show a field only if another field is empty) but BOTH of my fields are coming in through a nodereferrer relationship and I don't know how to craft the PHP.

If anyone can point to examples for showing a field only if another field is empty--when those fields are using relationships--that would be great.

Eng.HamadaEid’s picture

Hi All,
With Drupal Views, how can I hide a Field if another Field is not empty? In other words, how can I show a Field unless its empty, then show a different Field?

I have the following;

Node1 fieldA - text for field A in Node 1 fieldB - text for field B in Node 1

Node2 fieldA - (empty) fieldB - text for field B in Node 2

I want to show fieldA, unless it's empty in which case i wanted to show fieldB. So my View would show;

'text for field A in Node 1' 'text for field B in Node 2'

How can I do this? I can hide a filed if its empty, but how can I hide a field if another field is not being hidden?

In case it matters, the reason im doing this is im using image cache to generate thumbnails for a gallery. However for some thumbnails I want to be able to upload a different image to be used as a thumbnail. Thanks

cinetik’s picture

Hi Hamada,

Try this post : http://drupal.org/node/1240820

dmoonman’s picture

dmoonman’s picture

Oops nevermind!

samerjh’s picture

You can do this easily by the following steps (I've tried it in drupal 7):

  1. 1. Add both fields
  2. 2. make the first one invisible (exclude from display)
  3. 3. in the second field go to no result behavior tab.
  4. 4. write the token of the first field (example: [field_name]).

It should work, I hope it will work with you

patrickfgoddard’s picture

Yeah. This. Genius. Great tip, @samerjh. Thank you.

Saved me from getting beat up by crazy sales people at work. ;)

JKingsnorth’s picture

The solution in #10 is very excellent. Thanks!

JKingsnorth’s picture

Title: Still need help: Display field only if another field is empty » Display a field only if another field is empty
Project: Views Custom Field » Views (for Drupal 7)
Version: 6.x-1.x-dev » 7.x-3.x-dev
Component: Miscellaneous » Documentation
Category: Support request » Task
Issue summary: View changes

Since this issue is stale, I suggest adding the solution in #10 to documentation so that other people can find it useful. Perhaps in the main Views project though since it is relevant to all Views, not just the outdated Custom Views Field module.

jsheller’s picture

The solution #10 solved my problem, too! Thank you very much!

ssimmons’s picture

#10 worked for me too! Thanks @samerjh!

ehsankhfr’s picture

stefan93’s picture

tanks @samerjh for this trick it works

criscom’s picture

thanks @samerijh!
#10 works like a charm.

hhvardan’s picture

thanks @samerjh

jeromewiley’s picture

Category: Task » Support request
Priority: Normal » Minor
Status: Active » Fixed

Seems the poster needed some guidance on how to configure a Views field to show only if another field's value was empty.
Suggestion was provided and appears to work well.
Closing.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.