- Posts: 567
COMMUNITY FORUM
Hide extra field if value is empty
- Jiliko.net
- Offline
- Platinum Member
Less
More
14 years 8 months ago #71714
by Jiliko.net
Replied by Jiliko.net on topic Hide extra field if value is empty
A solution to do that :
add to the li element either the 'id' or 'class' property with the extrafield label
If the extrafield is empty add the class 'empty' to the li element
In css :
li.extrafieldlabel.empty {display:none} /* if you've chosen to add extrafield as class
li#extrafieldlabel.empty {display:none} /* if you've chosen to add extrafield as id
do that for each extrafield you want to hide if it's empty
Olivier
Darell Sison said:Devs? update please?
add to the li element either the 'id' or 'class' property with the extrafield label
If the extrafield is empty add the class 'empty' to the li element
In css :
li.extrafieldlabel.empty {display:none} /* if you've chosen to add extrafield as class
li#extrafieldlabel.empty {display:none} /* if you've chosen to add extrafield as id
do that for each extrafield you want to hide if it's empty
Olivier
Darell Sison said:Devs? update please?
Please Log in or Create an account to join the conversation.
- Geoffww
- Offline
- New Member
Less
More
- Posts: 8
14 years 8 months ago #71715
by Geoffww
Replied by Geoffww on topic Hide extra field if value is empty
The js worked perfectly thank you very much!
Olivier Nolbert said:The js solution (mootools) to fix the extrafields li odd/even classes
I think there's a php solution in the code i've previously posted but this one works.
Olivier
Olivier Nolbert said:The js solution (mootools) to fix the extrafields li odd/even classes
I think there's a php solution in the code i've previously posted but this one works.
Olivier
Please Log in or Create an account to join the conversation.
- Zach Schnackel
- Offline
- New Member
Less
More
- Posts: 19
14 years 8 months ago #71716
by Zach Schnackel
Replied by Zach Schnackel on topic Hide extra field if value is empty
Hey guys, just thought I would let you know I was able to figure out how to hide empty fields directly in your item.php file within your template. It works by slightly modifying the 'foreach' statement K2 uses to output the Extra Fields. What it is does run the check first for the extra fields and then checks to see if any extra fields are empty. If they are not, it does it's normal mojo, if any are, it outputs nothing. I've attached the PHP code. Let me know if you run into any issues. Thanks!
Please Log in or Create an account to join the conversation.
- Jiliko.net
- Offline
- Platinum Member
Less
More
- Posts: 567
14 years 8 months ago #71717
by Jiliko.net
Replied by Jiliko.net on topic Hide extra field if value is empty
Hi Zach,
Thanks for sharing your solution...
Just have to care about the extrafield link type which default value is 'http://'...A solution is to delete it in the extrafield form or to test the extrafield type in the k2 item.php. cf my item.php code above.
Olivier
Zach Schnackel said:Hey guys, just thought I would let you know I was able to figure out how to hide empty fields directly in your item.php file within your template. It works by slightly modifying the 'foreach' statement K2 uses to output the Extra Fields. What it is does run the check first for the extra fields and then checks to see if any extra fields are empty. If they are not, it does it's normal mojo, if any are, it outputs nothing. I've attached the PHP code. Let me know if you run into any issues. Thanks!
Thanks for sharing your solution...
Just have to care about the extrafield link type which default value is 'http://'...A solution is to delete it in the extrafield form or to test the extrafield type in the k2 item.php. cf my item.php code above.
Olivier
Zach Schnackel said:Hey guys, just thought I would let you know I was able to figure out how to hide empty fields directly in your item.php file within your template. It works by slightly modifying the 'foreach' statement K2 uses to output the Extra Fields. What it is does run the check first for the extra fields and then checks to see if any extra fields are empty. If they are not, it does it's normal mojo, if any are, it outputs nothing. I've attached the PHP code. Let me know if you run into any issues. Thanks!
Please Log in or Create an account to join the conversation.
- jamesrward
- Offline
- Junior Member
Less
More
- Posts: 25
14 years 8 months ago #71718
by jamesrward
Replied by jamesrward on topic Hide extra field if value is empty
Good work Zach. I noticed your solution will also suffer from potentially breaking the odd even row highlighting. This is easily corrected with something like:
$class = ($class == 'even') ? 'odd' : 'even';
and changing the echo statement to:
echo $class;
I also added a quick check for the link issue Olivier mentions above:
if((!empty($extraField->value)) && (($extraField->value) != "http://"))
See attached for a revised version.
$class = ($class == 'even') ? 'odd' : 'even';
and changing the echo statement to:
echo $class;
I also added a quick check for the link issue Olivier mentions above:
if((!empty($extraField->value)) && (($extraField->value) != "http://"))
See attached for a revised version.
Please Log in or Create an account to join the conversation.
- Zach Schnackel
- Offline
- New Member
Less
More
- Posts: 19
14 years 8 months ago #71719
by Zach Schnackel
Replied by Zach Schnackel on topic Hide extra field if value is empty
James,
Thanks for the fix, I really appreciate it!
Thanks for the fix, I really appreciate it!
Please Log in or Create an account to join the conversation.
- Heather
- Offline
- Junior Member
Less
More
- Posts: 35
14 years 8 months ago #71720
by Heather
Replied by Heather on topic Hide extra field if value is empty
You guys ROCK! I was just browsing and came across this and can use it SO much! WooOOooT!
Big hugs and smooches to those that take them... To the rest a proper handshake and a composed, "Thank you very much, Sir."
Big hugs and smooches to those that take them... To the rest a proper handshake and a composed, "Thank you very much, Sir."
Please Log in or Create an account to join the conversation.
- piperchick
- Offline
- Premium Member
Less
More
- Posts: 133
14 years 7 months ago #71721
by piperchick
Replied by piperchick on topic Hide extra field if value is empty
This works really well. Thanks so much for this advice.
Please Log in or Create an account to join the conversation.
- The White Alchemist S.L.
- Offline
- New Member
Less
More
- Posts: 16
14 years 5 months ago #71722
by The White Alchemist S.L.
Replied by The White Alchemist S.L. on topic Hide extra field if value is empty
This is so great!!
The only thing is that when i use k2 searchbox option results page show empty fields. any idea about how to avoid this?
Thanks a lot for such a nice improvement!
The only thing is that when i use k2 searchbox option results page show empty fields. any idea about how to avoid this?
Thanks a lot for such a nice improvement!
Please Log in or Create an account to join the conversation.
- Mauricio González
- Offline
- Senior Member
Less
More
- Posts: 41
14 years 5 months ago #71723
by Mauricio González
Replied by Mauricio González on topic Hide extra field if value is empty
OMG, found it on the first search. Amazing.
This should be implemented on the next release.
Thanks a lot guys.
This should be implemented on the next release.
Thanks a lot guys.
Please Log in or Create an account to join the conversation.