Skip Navigation

[Resolved] Conditional View

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to Hide topic title if there is no value available for topic

Solution:
You can use custom javascript/jQuery code to hide the topic title if there is no value to display under that specific topic.

You can find proposed solution with the following reply:
=> https://toolset.com/forums/topic/conditional-view-7/#post-631469

Relevant Documentation:

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by Ljuba 6 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#630422

I want to group several fields in one View and to display it trough Cintent Template (ie)
<h1>Title</h1>
[types field='field1'][/types]
[types field='field2'][/types]
[types field='field3'][/types]
[types field='field4'][/types]

- If user didn't filed any of above filed, they will not appear (that's great), but title will appear. I know how to disable title if fields are not field by user (add fields to condition one by one), but how to set if ANY OF FIELD is filed by user (to avoid hundred fields, one by one)?

P.S. If there is only option, one by one, just be brief and write it down.

#630523

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - the only way to display the field is to add its shortcode:

[types field='field1'][/types]

You can even copy/paste the shortcode and just change the field name. You do not need to add (add fields to condition one by one) if you want to hide title when there is no field value available. Instead you can use simple javascript/jQuery code to hide the title when there is no value for any field.

I can guide you in right direction if you want further help but I need problem URL and test case example to show/hide field for your view.

#630666

1) "You can even copy/paste the shortcode and just change the field name. You do not need to add (add fields to condition one by one) "

I know that, I just asked is it other option.

2) "if you want to hide title when there is no field value available. Instead you can use simple javascript/jQuery code to hide the title when there is no value for any field."

Yes, that is my main issue here and I will need help, please.

Please open private message channel to give you data for login.

#630802

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Please share problem URL where you want to display the fields.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#630999

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - we can not combine all tickets to one. As per our support policy we entertain only one question per ticket.

Also, you are in south America timezone that is totally contrary to my timezone. This will create long time gap for back and forth reply. If you want I can assign this ticket to support person who works in your timezone so that you will get quick replies. Let me know if you want to continue here or want support person in your timezone.

Regarding hiding the title - where you added the Types fields ‘Tipo de sitio’ to which section of template? I do not see anything like you shared in your initial reply:

<h1>Title</h1>
[types field='field1'][/types]
[types field='field2'][/types]
[types field='field3'][/types]
[types field='field4'][/types]

Where such fields added?

#631151
007.jpg
006.jpg
005.jpg
004.jpg
003.jpg
002.jpg
001.jpg

A) Well, maybe is best solution to forward topic, as it looks that you don’t follow me (see below) and you also have the right about time zone (but Toolset set you, not me). So, please andswer tonight and forward it (maybe Nigel?).

B) We can separate it all, but that is essentially the same issue in two topics (both active). One is about Elementor and Gallery (as there is the mess, as it works on localhost and not on live site). Second is ‘Conditional Grouping’ in View (two separate issues, I agree, but the same think as it is within the Field Group ‘Conditionals’).

VISUAL SUPPORT

I attached now images. There is visible that what I wrote in private message (Tipo de sitio).

1) Image 001 shows Dashboard with assigned single.php (‘Sitios Single’)
2) Image 002 shows that I in Custom Template of ‘Sitio Single’ inserted Elementor Template shortcode.
3) I already wrote that Elementor Template contain ‘mixed’ code content (open Elementor Template and see yourself – also):

- codes of the ‘modular’ Views’ (Maps, Gallery, … - see yourself available and used Views) – in further screenshots assigned as ‘Views shortcode’
- codes of DIRECTLY FIELDS in further screenshots assigned as ‘Field shortcode’

4) Image 003 shows Elementor Template View (see addressbar) and you can see that it render well Views shortcode and not render Fields shortcode (missing ‘Accidente geográfico’ - despite that it is in Template inserted).
5) Image 004 and 005 shows SITE POST VIEW (see addressbar – created site is ‘Playa de Canoa) and two sections where appear that if I use in Elementor Template directly field shorctodes, Elementor can be used to be created Custom Template (I didn’t tested all fields – obviously, to not waste the time). You can see that in direct shortcode Map also render custom PIN. On 004 you can see ‘No items found’ for View shortcode (not render it).

However, there is the problem with Gallery what in my localhost appear well and in cloned/migrated/restored copy online (you have access) – not appear well.

That's why I in other topic asked – is it some hidden problems there?

TOPIC

- You can see in image 003 and 004 Tipo de sitio (there is same Field Group) and Field ‘Accidente geográfico’ (last choice of field slug ‘espacio-geografico’).

- If Accidente geográfico is not selected, TITLE Tipo de sitio should not to appear. That’s the topic. We don’t need 20 (whatever number of fields), as one is enough. However, Field Group contain 19 fields and if you want, be free to add (but, no reasons for it, as this is for demonstration).

- So, you have

<h1>Title</h1>
[types field='field1'][/types]

as (today added and on Playa de Canoa page appear also - 'Formacion costera o oceánica' - under Field shorcode column - see image 006)

<h2><span style="color: #222222; font-size: 17px; font-weight: bold; line-height: 32px;">Tipo de sitio</span></h2>
[types field='espacio-geografico'][/types]<br>
[types field='espacio-urbano'][/types]<br>
[types field='espacio-rural'][/types]<br>
[types field='espacio-natural'][/types]<br>
[types field='accidente-geografico'][/types]<br>

- Your question - "Where such fields added? "
Answer - in Elementor Template [elementor-template id="391"] as 'New Sitio Template' (see image 007)

#631469

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - to hide the title if there is no field content available:

I've added the following code to "Sitios Single" Content Templates JS box:

jQuery(document).ready(function($){
  $('div#tipo-de-sitio p:empty').remove();
   if($('div#tipo-de-sitio p').length == 0){
      $('div#tipo-de-sitio h2').hide();
  }
});

I've wrap all your fields using div with ID: tipo-de-sitio - as you can see below:

<div id="tipo-de-sitio">
<h2><span style="color: #222222; font-size: 17px; font-weight: bold; line-height: 32px;">Tipo de sitio</span></h2>
<p>[types field='espacio-geografico'][/types]</p>
<p>[types field='espacio-urbano'][/types]</p>
<p>[types field='espacio-rural'][/types]</p>
<p>[types field='espacio-natural'][/types]</p>
<p>[types field='accidente-geografico'][/types]</p>
</div>

Nnow when you should add any new shortcode add it to <p> tag for this section or for all other section and wrap with unique div id and use the same method to hide the title if no content to display.

#632149

Thanks.