Keyword

Hide extra field if value is empty

  • Nick
  • Nick's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 3 weeks ago #71754 by Nick
Replied by Nick on topic Hide extra field if value is empty
i'm not sure if you can style each field since they are generated with a "while" statement in php (while there are fields in the group, it will display them) So it's not like they are hard coded somewhere.

The only solution i can think of is to create some sort of php function and a field inside the extra fields table in mysql which caries the styling. Then have php parse out the style and apply it to the actual field when it's being rendered. But that's just what i can come up with now. You can also do it with javascript but not sure how.

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

More
14 years 3 weeks ago #71755 by Peter Monti
Replied by Peter Monti on topic Hide extra field if value is empty
i found this post here  but im not understanding how to do them all? i jsut want each field to have an icon rather than text and the link within that icon.and when there is no link inserted the icon does not show.....this si the code from the other post but im not getting it! thanks for your help nick
adding this line <?php $custom = $this->item->extra_fields; ?> and then addressing extra fields for the item like <?php echo $custom[1]->value;? as long as the order of the fields is static.

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

  • Nick
  • Nick's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 3 weeks ago #71756 by Nick
Replied by Nick on topic Hide extra field if value is empty
Gimme a sec. I'll whip up the code for this for you. How many extra fields do you have?

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

More
14 years 3 weeks ago #71757 by Peter Monti
Replied by Peter Monti on topic Hide extra field if value is empty
8 in total
wow thanks alot....ive been going nutz here

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

  • Nick
  • Nick's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 3 weeks ago #71758 by Nick
Replied by Nick on topic Hide extra field if value is empty
go here:
pastebin.com/Fr8L6Vza

rename your old item.php to something else.

paste the code from pastebin in a new item.php

tell me the results pls :)

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

More
14 years 3 weeks ago #71759 by Peter Monti
Replied by Peter Monti on topic Hide extra field if value is empty
awsome..........so now the name of the field doesnt shhow which is perfect...how can i now style each individual field with its own icon? sorry to ruin your sunday nick........thanks again!

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

  • Nick
  • Nick's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 3 weeks ago #71760 by Nick
Replied by Nick on topic Hide extra field if value is empty
well you need to open up dreamweaver or whatever and go to line 263. That's where the magic happens. There you can give each
tag it's own style.

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

More
14 years 3 weeks ago #71761 by Peter Monti
Replied by Peter Monti on topic Hide extra field if value is empty
ok perfect - can i take the fields out of the unordered list and just have a div defining each field?

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

  • Nick
  • Nick's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 3 weeks ago #71762 by Nick
Replied by Nick on topic Hide extra field if value is empty
sure

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

More
14 years 2 weeks ago #71763 by Wouter
Replied by Wouter on topic Hide extra field if value is empty
I've implemented the hacks succesfully.

 

But is there a way to show only the first 4 extra fields in category view? And then show all extra fields in the item view?

 

I have about 15 extra fields.

 

Thanks in advance!

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

  • Nick
  • Nick's Avatar Topic Author
  • Offline
  • Elite Member
More
14 years 2 weeks ago #71764 by Nick
Replied by Nick on topic Hide extra field if value is empty
yes. go to my pastebin post here : pastebin.com/Fr8L6Vza

 

and copy from line 254 to 272 and replace your original extra fields section with that one. then remove lines 265 to 268. That's a very quick fix to your problem. I am not on my computer right now so i can't write out a prettier code. this should fix the problem. You have to put the code in item_list.php i think.

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

More
14 years 1 week ago #71765 by Wouter
Replied by Wouter on topic Hide extra field if value is empty
I've implemented this fix, but nothing happens (all my extra fields are now gone!) I've put this hack in the category_item.php.

 

 

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

More
14 years 1 week ago #71766 by Wouter
Replied by Wouter on topic Hide extra field if value is empty
I've found it!

 

I've changed the code in category_item.php to:

 

<?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?>         <!-- Item extra fields -->        <div class="itemExtraFields">            <h3><?php echo JText::_('Additional Info'); ?></h3>            <ul>                <?php $exfields = $this->item->extra_fields; ?> <!--This part puts the extra fields in a variable-->                <li>                    <span class="itemExtraFieldsLabel"><?php if($exfields[1]->value) echo $exfields[1]->name;?></span>                    <span class="itemExtraFieldsValue"><?php if($exfields[1]->value) echo $exfields[1]->value;?></span>                </li>                <li>                    <span class="itemExtraFieldsLabel"><?php if($exfields[2]->value) echo $exfields[2]->name;?></span>                    <span class="itemExtraFieldsValue"><?php if($exfields[2]->value) echo $exfields[2]->value;?></span>                </li>                            <li>                    <span class="itemExtraFieldsLabel"><?php if($exfields[3]->value) echo $exfields[3]->name;?></span>                    <span class="itemExtraFieldsValue"><?php if($exfields[3]->value) echo $exfields[3]->value;?></span>                </li>                <li>                    <span class="itemExtraFieldsLabel"><?php if($exfields[4]->value) echo $exfields[4]->name;?></span>                    <span class="itemExtraFieldsValue"><?php if($exfields[4]->value) echo $exfields[4]->value;?></span>                </li>            </ul>            <div class="clr"></div>        </div>        <?php endif; ?>

 

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

More
13 years 10 months ago #71767 by Bjern Potgieter
Replied by Bjern Potgieter on topic Hide extra field if value is empty
I know this is old but for anyone searching these forums, you can find a tutorial on hiding extra empty fields at: toxzen.co.za/webdevoloper/item/34-hide-empty-k2-extra-fields-in-joomla

It's literally 2 lines of code you can add.

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


Powered by Kunena Forum