Skip Navigation

[Resolved] Using selection box value in conditional field

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

Problem:

The issue here is that you are unable to use the checkboxes field in a conditional block with Toolset

Solution:

A ticket has been created internally regarding this issue for our developers to improve on this to allow for checkboxes fields to be evaluated here.

For now you will need to use the conditional shortcode itself to evaluate checkboxes fields.

An example of this can be see in the forum response at the link below.
https://toolset.com/forums/topic/using-selection-box-value-in-conditional-field/#post-1986973

This support ticket is created 3 years, 9 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 10 replies, has 2 voices.

Last updated by michielM 3 years, 8 months ago.

Assisted by: Shane.

Author
Posts
#1980669
Screenshot 2021-03-10 at 10.34.38.png

Tell us what you are trying to do?
I want to use a value out of three possibilities of a selection box field (set up in screenshot). The problem is that when the field is checked more than once, I don't know how to test for the other values.

I want to show an icon based on what type an Ambassador is: TA, VR or HT. In the conditional block I can only test for equal or not equal, whereas I would like to check if it CONTAINS, much like taxonomies.

Debug output:

####################
wpv-conditional attributes
####################
Array
(
    [if] =>   ( ( $(wpcf-gastdocent-type) = 'TA' ) OR ( $(wpcf-gastdocent-type) = 'Techniek Ambassadeur' ) ) 
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression:   ( ( $(wpcf-gastdocent-type) = 'TA' ) OR ( $(wpcf-gastdocent-type) = 'Techniek Ambassadeur' ) ) 
--------------------
--------------------
Converted expression: ( ( 'TA' = 'TA' ) OR ( 'TA' = 'Techniek Ambassadeur' ) )
--------------------
####################
wpv-conditional attributes
####################
Array
(
    [if] =>   ( ( $(wpcf-gastdocent-type) = 'VR' ) OR ( $(wpcf-gastdocent-type) = 'Vrouwelijke technici' ) ) 
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression:   ( ( $(wpcf-gastdocent-type) = 'VR' ) OR ( $(wpcf-gastdocent-type) = 'Vrouwelijke technici' ) ) 
--------------------
--------------------
Converted expression: ( ( 'TA' = 'VR' ) OR ( 'TA' = 'Vrouwelijke technici' ) )
--------------------
####################
wpv-conditional attributes
####################
Array
(
    [if] =>   ( ( $(wpcf-gastdocent-type) = 'HT' ) ) 
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression:   ( ( $(wpcf-gastdocent-type) = 'HT' ) ) 
--------------------
--------------------
Converted expression: ( ( 'TA' = 'HT' ) )
--------------------

Is there any documentation that you are following?
https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/

What is the link to your site?
hidden link

#1981129

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Michiel,

Thank you for getting in touch.

We actually don't have a contains function that would operate in this fashion, however you can do your conditionals based on which option is checked using the options attribute for the field.

Example

[wpv-conditional if="('[types field='gastdocent-type' option='0'][/types]'  eq 'TA' ) OR ('[types field='gastdocent-type' option='1'][/types]'  eq 'VR' )"]

Each option value will represent the position of your checkbox, option 0 is the first selectable option while option 1 is the second selectable option.

Please let me know if this helps.
Thanks,
Shane

#1981135

Hi Shane,

It works if I add an extra space at the end of the string I compare to. So, " eq 'TA ' " works, " eq 'TA' " doesn't work. Why is that?

Full working code:

[wpv-conditional if="('[types field='gastdocent-type' option='0'][/types]'  eq 'TA ' ) OR ('[types field='gastdocent-type' option='1'][/types]'  eq 'VR ' )"]
#1981137

Oh, can I use this condition in the Advanced Editor of the Conditional Block?

#1981309

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Michiel,

Unfortunately the only way this will work is by manually using the conditional shortcodes. I've found that evaluating the checkboxes in the conditional block is not functioning correctly as such I've escalated the issue to our second tier supporters for further advise on the one.

I will post an update once they get back to me.

Thanks,
Shane

#1982579

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Michiel,

Our 2nd tier team reported that we have an existing ticket on this issue as a Feature Request. At this point in time it's not scheduled to be worked on and it could be some time before this happens.

Right now the best workaround is to manually use the conditional shortcodes with the Toolset Types shortcode to pick off the checkboxes.

Thanks,
Shane

#1986801

Hi Shane,

Thanks for that but can you give me a working example with an image inside the conditional? As this is currently not working on my site (i.e. the image inside doesn't show when the condition is met).

Cheers, Michiel

#1986973

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Michiel,

The shortcode below should provide the correct conditions for this to work.

[wpv-conditional if="('[types field='gastdocent-type' option='0'][/types]'  eq 'TA ' ) OR ('[types field='gastdocent-type' option='1'][/types]'  eq 'VR ' )"]

Image shortcode goes here.

[/wpv-conditional]

Remember I mentioned that you won't be able to hide a block with this method because you're not able to evaluate checkboxes inside the GUI.

Perhaps I need to have a look at what you're actually doing to see what is happening. I saw that you mentioned that you have to put an extra space in the value to evaluate e.g "TA " and not "TA". For this I would recommend checking the values in the custom field itself to ensure that there is no space added.

Thanks,
Shane

#1987137

Where would you put this code? In the ToolSet Fields & Text block, this didn't work. Would you use a paragraph or custom HTML?

#1987231

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Michiel,

This can be added to the Toolset Fields and Blocks. If it didn't work I will need to have a look at the site to see exactly why it's not working.

Can you provide the admin access as well as a link to the page where you are testing this out.

Thanks,
Shane

#1991957

I had to put the shortcodes in a HTML-block. This will be hard for non-programmers to change, so it's not ideal. Please let me know when the Feature Request is planned to be implemented.