Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
dawehnerViews is not a support queue for views custom field.
Move to views custom field . They know the module much better than everything else here.
Comment #2
rpk CreditAttribution: rpk commentedComment #3
Edward Andrews CreditAttribution: Edward Andrews commentedI use code like this to print an email address - the permission tick box is set to store hide or show:
Hope that's useful.
Edward
Comment #4
rpk CreditAttribution: rpk commentedHi 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!
Comment #5
lunk rat CreditAttribution: lunk rat commentedI 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.
Comment #6
Eng.HamadaEid CreditAttribution: Eng.HamadaEid commentedHi 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
Comment #7
cinetik CreditAttribution: cinetik commentedHi Hamada,
Try this post : http://drupal.org/node/1240820
Comment #8
dmoonman CreditAttribution: dmoonman commentedComment #9
dmoonman CreditAttribution: dmoonman commentedOops nevermind!
Comment #10
samerjh CreditAttribution: samerjh commentedYou can do this easily by the following steps (I've tried it in drupal 7):
It should work, I hope it will work with you
Comment #11
patrickfgoddard CreditAttribution: patrickfgoddard commentedYeah. This. Genius. Great tip, @samerjh. Thank you.
Saved me from getting beat up by crazy sales people at work. ;)
Comment #12
JKingsnorth CreditAttribution: JKingsnorth commentedThe solution in #10 is very excellent. Thanks!
Comment #13
JKingsnorth CreditAttribution: JKingsnorth commentedSince 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.
Comment #14
jsheller CreditAttribution: jsheller commentedThe solution #10 solved my problem, too! Thank you very much!
Comment #15
ssimmons CreditAttribution: ssimmons commented#10 worked for me too! Thanks @samerjh!
Comment #16
ehsankhfr CreditAttribution: ehsankhfr commentedProbably it can be another solution:
https://api.drupal.org/api/examples/form_example%21form_example_states.i...
Comment #17
stefan93 CreditAttribution: stefan93 commentedtanks @samerjh for this trick it works
Comment #18
criscomthanks @samerijh!
#10 works like a charm.
Comment #19
hhvardan CreditAttribution: hhvardan commentedthanks @samerjh
Comment #20
jeromewiley CreditAttribution: jeromewiley commentedSeems 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.