- Posts: 567
COMMUNITY FORUM
Hide extra field if value is empty
- Jiliko.net
-
- Offline
- Platinum Member
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
- Posts: 8
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
- Posts: 19
Please Log in or Create an account to join the conversation.
- Jiliko.net
-
- Offline
- Platinum Member
- Posts: 567
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
- Posts: 25
$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
- Posts: 19
Thanks for the fix, I really appreciate it!
Please Log in or Create an account to join the conversation.
- Heather
-
- Offline
- Junior Member
- Posts: 35
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
- Posts: 133
Please Log in or Create an account to join the conversation.
- The White Alchemist S.L.
-
- Offline
- New Member
- Posts: 16
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
- Posts: 41
This should be implemented on the next release.
Thanks a lot guys.
Please Log in or Create an account to join the conversation.
- Bernd
-
- Offline
- New Member
- Posts: 11
Aleksandr said:Hi guys, thanks for all your time!
I've just started to use K2 and I am not that technical to understand the mod. Could you please explain what file should I change to hide the empty fields..??
Thanks!
Please Log in or Create an account to join the conversation.
- Bernd
-
- Offline
- New Member
- Posts: 11
Please Log in or Create an account to join the conversation.
- Marcus Baumgarten
-
- Offline
- New Member
- Posts: 1
I tried your code snippet to hide empty fields, but it doesn't work for me. Can you say in which position (line) you change the item.php? In my case I see the additional infos twice (see the image).
What's the problem?
BTW: the empty field is really hidden :-)
Thanx
Please Log in or Create an account to join the conversation.
- delvasse
-
- Offline
- New Member
- Posts: 1
Yes, empty textareas are still visible. Big drawback. The length of empty textareas string is 6...
We can add such a test :
if ($extraField->type == "textarea" && (strlen($extraField->value) < 7)) { $extraField->value = ""; }
before the main test : if(!empty($extraField->value))
Regards,
Bernard Delvasse
Please Log in or Create an account to join the conversation.
- Jiliko.net
-
- Offline
- Platinum Member
- Posts: 567
I think you see the info twice because you have to REPLACE and not ADD the modified code to your item.php
In v2.3, in item.php, it's from line 254 to 268
Olivier
Marcus Baumgarten said:Hi Olivier,
I tried your code snippet to hide empty fields, but it doesn't work for me. Can you say in which position (line) you change the item.php? In my case I see the additional infos twice (see the image).
What's the problem?
BTW: the empty field is really hidden :-)
Thanx
Please Log in or Create an account to join the conversation.
- ak2user
-
- Offline
- New Member
- Posts: 19
I attempted to implement this hack. Please see attached file for details. And get exactly nothing as a result, i.e. empty fields are still displayed as empty fields, just like without the hack.
Any suggestions?
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
Please Log in or Create an account to join the conversation.
- ak2user
-
- Offline
- New Member
- Posts: 19
I then applied the same modification to category_item.php and that worked as well, which is great. But there is a small problem here. Stylistic information is gone. I wonder whether I will be able to recreate it with css, or perhaps someone could alter this hack specifically for category_item.php.
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
- Posts: 3722
that may be the problem
Please Log in or Create an account to join the conversation.
- ak2user
-
- Offline
- New Member
- Posts: 19
Please Log in or Create an account to join the conversation.