I hope this is the right place to post this. I'm using Addresses to make a simple CRM and have set my Addresses format as follows:

[addresses_aname_hcard] [addresses_is_primary_hcard]
[addresses_street_hcard]
[addresses_city_hcard], [addresses_province_name_hcard] [addresses_postal_code_hcard]
[addresses_country_name_hcard]
Phone: [addresses_phone_plain]<br/>
Fax: [addresses_fax_plain]<br/>
Toll free: [addresses_additional_plain]

I'm using the "Additional" field for a Toll Free phone number and I would like to insert a conditional to only show that field when it contains data. Is there a way to do that?

Thanks,
Andrew

Comments

AlexisWilke’s picture

Hi Andrew,

Unfortunately, no... there is no condition support. However I agree that would be nice.

Thank you.
Alexis Wilke

awasson’s picture

Hi Alexis,
Thanks for the reply. Maybe in a future update it will be added. If I come up with a patch, I'll be sure to post it. In the meantime I've come up with a workaround using jQuery. It's pretty easy and works as follows:

I changed my addresses formats so that the field I want to show or hide is wrapped in a div with a class that I can identify it with (class="toll-free").

<div class="toll-free">Toll free: [addresses_additional_plain]</div>

Then I added some jQuery to the header of my view to loop through all of the divs that have that class. If they only contain the text "Toll free", I clear the text.

drupal_add_js (
	'$(document).ready(function() { 
		$("div.toll-free").each(function() {
    		if($.trim($(this).text()) == "Toll free:") {
    			$(this).text("");
    		}
		});
  });', 'inline');

Pretty simple but it does the job.

Cheers,
Andrew

AlexisWilke’s picture

Thank you for sharing! 8-)
Alexis