Skip Navigation

[Resolved] Conditional display form fields

This support ticket is created 4 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by Waqar 4 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#1575507
fields.PNG
cond.PNG

I have created a custom post type called Tickets with a custom taxonomy called Ticket Categories.

I have created a form so users can create Ticket posts from the front end. I want to show a group of custom fields depending what ticket category the user selects.

i.e

If they select ticket category A - show all fields from a conditional group of fields
If they select ticket category B - show all fields from a conditional group of fields

I think I am on the right track but not sure what to add in the conditional group settings. (see screenshot)

So in the screenshot provided I want to show the conditional group (which holds the HR rep field) IF the ticket category called "Job Advert" is selected on the front end)

#1576681

Hi Stewart,

Thank you for contacting us and I'd be happy to assist.

To show or hide a conditional field group based on a taxonomy field value, you can follow these steps:

1. In the conditional field group's settings, you'll see the option "Edit conditions manually".

Example screenshot: hidden link

2. In that manual condition field, you can include a condition for the taxonomy field, like this:


$(book-type) eq '6'

Example screenshot: hidden link

Note: You'll replace "book-type" with the actual slug of your taxonomy "Ticket Categories" and "6" with the actual ID of the target term in that taxonomy.

As a result, the fields inside this conditional field group will only show, once that term gets selected.

Here is a detailed guide on this topic:
https://toolset.com/documentation/user-guides/front-end-forms/cred-conditional-display-engine/

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1578477
correct.PNG
job.PNG

That worked perfectly thank you!

One last thing. The category select drop-down is defaulting to the job category. This means that field shows by default. I want all conditional fields to be hidden by default so need the category select to default to say something like select category. So the field doesn't show unless the category is selected

#1581835

Thanks for the update and glad that it worked.

I'm afraid, there is no built-in option to add a default empty option in the taxonomy selection field, but you're welcome to submit this as a feature request:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

For now, a workaround can be to include a custom script in form's "JS editor" tab, to dynamically insert this default option:
( example screenshot: hidden link )


jQuery(document).ready(function() {
	var option = new Option('-- select --', ''); jQuery('select.wpt-form-select.form-select').prepend(jQuery(option)).val('');
});

I hope this helps and for more personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/