Keyword

Hide extra field if value is empty

More
15 years 1 month 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?

Please Log in or Create an account to join the conversation.

More
15 years 1 month 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

Please Log in or Create an account to join the conversation.

More
15 years 1 month 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.

More
15 years 1 month 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!

Please Log in or Create an account to join the conversation.

More
15 years 1 month 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.

Please Log in or Create an account to join the conversation.

More
15 years 1 month 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!

Please Log in or Create an account to join the conversation.

More
15 years 1 month 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."

Please Log in or Create an account to join the conversation.

More
15 years 3 weeks 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.
  • The White Alchemist S.L.'s Avatar
  • Offline
  • New Member
More
14 years 10 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!

Please Log in or Create an account to join the conversation.

  • Mauricio González
  • Mauricio González's Avatar
  • Offline
  • Senior Member
More
14 years 10 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.

Please Log in or Create an account to join the conversation.

More
14 years 8 months ago #71724 by Bernd
Replied by Bernd on topic Hide extra field if value is empty
You need to change the item.php

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.

More
14 years 8 months ago #71725 by Bernd
Replied by Bernd on topic Hide extra field if value is empty
Fantastic hack, but I've the problem, that empty textareas are still visible.

Please Log in or Create an account to join the conversation.

More
14 years 7 months ago #71726 by Marcus Baumgarten
Replied by Marcus Baumgarten on topic Hide extra field if value is empty
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.

More
14 years 7 months ago #71727 by delvasse
Replied by delvasse on topic Hide extra field if value is empty
Hello Bernd,

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.

More
14 years 7 months ago #71728 by Jiliko.net
Replied by Jiliko.net on topic Hide extra field if value is empty
Hi Marcus,

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.

More
14 years 7 months ago #71729 by ak2user
Replied by ak2user on topic Hide extra field if value is empty
Hello folks,

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?
Attachments:

Please Log in or Create an account to join the conversation.

More
14 years 7 months ago #71730 by william white
Replied by william white on topic Hide extra field if value is empty
Try the file by Oliver on page 1 of this post

Please Log in or Create an account to join the conversation.

More
14 years 7 months ago #71731 by ak2user
Replied by ak2user on topic Hide extra field if value is empty
Apologies. The hack does work as intended for item.php. I modified item.php but was looking at the category listing, hence my previous statement.

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.

More
14 years 7 months ago #71732 by william white
Replied by william white on topic Hide extra field if value is empty
Check the first linethis would be different than the original which was
that may be the problem

Please Log in or Create an account to join the conversation.

More
14 years 7 months ago #71733 by ak2user
Replied by ak2user on topic Hide extra field if value is empty
The code (that is being replaced) in item.php and category_item.php is different. As I said, the hack works fine for item.php for which it was intended. But when I apply it for category_item.php, there is a mismatch with css. So either the hack needs to be reworked specifically for category_item.php or css adjusted.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum