This topic is locked

Skip blank fields?

3/1/2009 12:27:09 AM
PHPRunner General questions
R
rgfischerjr author

I have formatted addresses in list and print views as follows:
Address
Suite
City,   State   Zip
Which outputs nicely:
Address

Suite

City, State Zip

Not all address have a suite, so the list view has a blank line:
Address
City, State Zip
What is the best way to remove the blank line for addresses that have no suite number?
thanks,

Raymond

J
Jane 3/2/2009

Raymond,
you can hide empty field with
in theList page: After record processed event:

global $record;

if (!$data["FieldName"])

$record["FieldName_fieldcolumn"] = false;


{BEGIN FieldName_fieldcolumn}

...

{$FieldName_value}


{END FieldName_fieldcolumn}

D
Denton 3/4/2009

Hi Jane.

I'm clueless when it comes to php. Can you please elaborate on your instructions? There are 2 pieces of code - what goes where?
Actually, I am trying to do something different (I think). If I have a column in the list page which contains no data, is there a way to hide the whole column?
Thanks,
Denton

M
mmponline 3/4/2009

Sure Jane will explain, but how magic would it be to have a tick option on a field's propperties for "Hide when field is empty". Doing it manually as she explains, takes some time, and when a page reset is needed (happens lees often but still does) the code needs to be added to each field manually again.

J
Jane 3/4/2009

Denton,
unfortunately it's impossble to hide whole column on the list page because you can check fields values when column header was filled.

R
rgfischerjr author 3/4/2009

Raymond,

you can hide empty field with
in theList page: After record processed event:


Jane - I owe you a bit more of an explanation:
Original code generated is:
{BEGIN streetAddress_fieldcolumn}

<td align=center valign=top class=borderbody

{$streetAddress_style}>

{$streetAddress_value}

</td>

{END streetAddress_fieldcolumn}

{BEGIN suite_fieldcolumn}

<td align=center valign=top class=borderbody

{$suite_style}>

{$suite_value}

</td>

{END suite_fieldcolumn}

{BEGIN city_fieldcolumn}

<td align=center valign=top class=borderbody

{$city_style}>

{$city_value}

</td>

{END city_fieldcolumn}

{BEGIN state_fieldcolumn}

<td align=center valign=top class=borderbody

{$state_style}>

{$state_value}

</td>

{END state_fieldcolumn}

{BEGIN zipCode_fieldcolumn}

<td align=center valign=top class=borderbody

{$zipCode_style}>

{$zipCode_value}

</td>

{END zipCode_fieldcolumn}
I then merge the columns resulting in this code:
{BEGIN streetAddress_fieldcolumn}<TD class=borderbody vAlign=top align=middle colSpan=5 {$streetAddress_style}>

{$streetAddress_value} &nbsp;{$suite_value} &nbsp;{$city_value} &nbsp;{$state_value} &nbsp;{$zipCode_value}

</TD>{END streetAddress_fieldcolumn}
I strip out the undesired &nbsp; and insert
resulting in this code:
{BEGIN streetAddress_fieldcolumn}<TD class=borderbody vAlign=top align=middle colSpan=5 {$streetAddress_style}>

{$streetAddress_value}
{$suite_value}
{$city_value}, &nbsp;{$state_value} &nbsp;{$zipCode_value}

</TD>{END streetAddress_fieldcolumn}
Which displays the address 'correctly' in a single column:
Street

Suite

City, State ZipCode
There is not always a suite associated with an address so I need to drop the {$suite_value}
from the list.
I understand from your example how it would work if the fields were not merged - but how can I accomplish with the merge?
Thanks,

Raymond

J
Jane 3/5/2009

Hi,
please see my changes in Bold:

{BEGIN streetAddress_fieldcolumn}<TD class=borderbody vAlign=top align=middle colSpan=5 {$streetAddress_style}>

{$streetAddress_value}
{BEGIN suite_fieldcolumn}{$suite_value}
{END suite_fieldcolumn} {$city_value}, &nbsp;{$state_value} &nbsp;{$zipCode_value}

</TD>{END streetAddress_fieldcolumn}


global $record;

if (!$data["suite"])

$record["suite_fieldcolumn"] = false;