Skip Navigation

[Resolved] Conditional form on empty value

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

Problem:
The user would like to display some fields, on a form, when a relationship field has a value.

Solution:
Currently, Forms do not have a way to conditionally display fields based on a "relationship" field. We can work around this limitation with a custom Javascript code

Check this example: https://toolset.com/forums/topic/conditional-form-on-empty-value/#post-1777417

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/forms/cred-conditional-display-engine/

This support ticket is created 3 years, 6 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 – 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: Africa/Casablanca (GMT+00:00)

This topic contains 7 replies, has 2 voices.

Last updated by heikoS 3 years, 6 months ago.

Assisted by: Jamal.

Author
Posts
#1773507

Hi,

thank you for your answer. Before I try to do that on my own, I have a simmilar question.

I made a conditional group in a form, where the user have to choose from a dropdown with parent informations. The parent (company) from the owner is shown. I try to show the group, if the user selected his company.

[cred_show_group if=“ ($ (job-company.parent) ??????? “ mode=„fade-slide“]
[/cred_show_group]

What do I have to fill instead of the ??????? to get this check if it not empty? I read the documentation and try it with some of the booleans like !EMPTY, but nothing is working.

Thank you for helping me to understand toolset a little bit better.

#1773547

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello.

You can test if the value of field is different than an empty string.

[cred_show_group if="( $(job-company.parent) ne '' )" mode="fade-slide"]

[/cred_show_group]

I hope this helps. Let me know what you will get.

#1773557

Hello,

I tried it but no reaction.

By the way, I made a little mistake. It has to be : company-job.parent

#1774075

Hello Jamal,

to make my previous reply clear, it is still not working.

If you have a bunch of ideas, I'll try them all 🙂

Heiko

#1777417

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

My apologies for the late reply, but I do not work on Sundays and Mondays.

I created a test site and a 1-to-many relationship between CPTs "Company" and "Jobs", and it turns out, that we can't have conditional display of fields based on relationships, it is only possible with custom fields and taxonomy terms. That is also documented here https://toolset.com/documentation/programmer-reference/forms/cred-conditional-display-engine/

I am really sorry, I did not check this for the first time.

The workaround that remains, is to use custom Javascript code to show/hide a section based on the value of the relationship field in the form. I created an example where we hide the submit button until a parent has been entered with the following Javascript code:

jQuery(function($){
  var select = $('select[name="@company-job.parent"]');
  var form = select.closest('form');
  var submit = form.find('input[type=submit]');

  if (select.val() == '') submit.hide();

  select.on('change',function(){
    if (select.val() == '') submit.hide();
    else submit.show();
  })
})

You can check my example on the following site hidden link

I hope this helps. Let me know if you have any questions.

#1777443

Hi Jamal,

my last reply was only to prevent a misunderstanding of the previous reply. I know your work days.

Thank you for the snippet. I‘ll try it the next days and come back to you.

Have a nice day!

#1777497

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Thank you for your feedback.

I'll set the ticket as waiting for your reply, it should be kept open for 3 weeks.

Have a nice day as well 🙂

#1782481

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.