Skip Navigation

[Resolved] Dependent dropdowns in a post form

This support ticket is created 5 years, 3 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 16 replies, has 2 voices.

Last updated by davidS-63 5 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#1490421

Tell us what you are trying to do?
I have CPT States, CPT Regions and CPT Specialists - all together connected with proper relationships.
I decided to make the States/regions as CPT because I was learning with the Real estate Toolset training page and there is a similar setup, I also use State/regions dropdowns in my custom search and though I can use these dropdowns on post form as well.

But I can't as the two dropdowns are not dependent on each other, so when the user selects a state, the second dropdown shows all regions instead of the ones related to the before selected state.

I discussed possible solutions on Toolset Facebook group, but with nearly no success. I read multiple support threads, but it either won't fit my setup or the solution/workaround was too advanced for me.

Many people suggested making the states and regions taxonomies again, but it won't solve my issue and I am not sure if I could make a similar custom search with taxonomies.

The last solution (not my favorite) would be to connect Specialists and States/regions manually, is that how its supposed to work on your real estate training site?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
hidden link

#1490917

Shane
Supporter

Languages: English (English )

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

Hi David,

Thank you for getting in touch.

Unfortunately at the moment there is no way to create a dependent field in our plugins. You will essentially need to connect the items manually.

Secondly the next best solution is that you create conditional fields. Example if you have a single field called State which is a select field, the next thing you will have is cities. However you will need to create a separate dropdown for each state's city and add field conditionals.

This way only the city that are in the selected states will show up.

Please let me know if this is clear.

Thanks,
Shane

#1492151

Hello Shane,

I tried the solution you suggested and it works for me it seems.

But it works only in back-end and post form, I will need it in custom search as well.

I tried to use the conditional output in custom search but it does not work, the conditions are the same as in post form:

Custom search setup:

<div class="form-group">
<label for="wpv-wpcf-stat">[wpml-string context="wpv-views"]Stát[/wpml-string]</label>
[wpv-control-postmeta type="select" field="wpcf-stat" url_param="wpv-wpcf-stat"]
</div>

[wpv-conditional if="( $(wpcf-stat) eq '1' )"]<label for="wpv-wpcf-mesto-sr">[wpml-string context="wpv-views"]město sr[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-mesto-sr" url_param="wpv-wpcf-mesto-sr"][/wpv-conditional]

Thanks in advance!

David

#1492259

Shane
Supporter

Languages: English (English )

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

Hi David,

So for you the custom search it wont work like this.

Have a look at this link below.
https://toolset.com/documentation/user-guides/views/front-page-filters/advanced-settings-custom-search/#dependent-parametric-search

You will need to set your filters to disappear based on the initial options that the user chooses. So if the choose California, only the options for California will appear.

Please let me know if this helps.
Thanks,
Shane

#1492353

Thanks Shane,

I 've read this documentation a hundred times...
How do I set the filters to disappear? By "Show only available options for each input"?

I tried numerous times all possible settings again, I did not find a solution and I messed up even worse 🙁

Do you have any working example with dependent parametric search?

All I need is to somehow achieve the States/Cities dropdowns you have at hidden link but not using relationships (as I have one relationship filter in the custom search already)

Regards

David

#1492537

Shane
Supporter

Languages: English (English )

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

Hi David,

This exact filter you are referring to will only for only relationship filters.

Would you min allowing me to have admin access to the site so that I can take a deeper look at this for you ?

Thanks,
Shane

#1492647

Shane
Supporter

Languages: English (English )

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

Hi David,

I had a look at this for you.

From what I see the filters are already dependent on each other. If you select an option from "Stát" then the filter "Město-čr" will only display the options relevant to the Stat filter.

What I did was to add a default value so when no option is selected the filter resets.

Thanks,
Shane

#1492699

Hi Shane,

Sorry, I guess I made a mistake somewhere else before...

it does display only the options relevant to the Stat filter because the "mesto-cr" is a select custom field which is appearing only when in Stat select custom field is selected the state relevant to "mesto-cr" / conditonal display ( Stát = 1) in the back-end.

And I did the same with another state (sr) so I have "mesto-sr" to show only if (Stát = 2)

Thank you for your patience, much appreciated!

David

#1495125

Shane
Supporter

Languages: English (English )

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

Hi David,

Happy I'm able to assist.

Is everything clear or do you still need some assistance, I wasn't able to tell from your previous post.

Thanks,
Shane

#1495703

Hi Shane,

Sorry, I still need assistance.

Because the mesto-cr is always there it does not disappear = when someone pick the other state (sr), the mesto-cr will be still there, but without options... I would need the mesto-sr dropdown to appear instead.

In the back-end I pick state, when I pick state (cr) the "mesto-cr" will appear. When I pick "sr", the mesto-sr will appear.

Thank you

#1496739

Shane
Supporter

Languages: English (English )

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

Hi David,

Given that this is a frontend filter then the filter itself won't dissappear, only the values itself will disappear in that filter.

In order to make the entire filter disappear you will need to use some custom code to check if the select field has any select options and then hide it if it doesn't.

Thanks,
Shane

#1498019

Hi Shane,

That would be totally fine that only values appear/disappear in the front-end filter, but I need the values to change based on the selection of the first filter.

So:

In the front-end filter, I pick a state, when I pick state "cr" the values of "mesto-cr" will appear. When I pick "sr", the values for mesto-sr will appear in the second filter.

Thank you,

David

#1498271

Shane
Supporter

Languages: English (English )

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

Hi David,

Ok so you are adding multiple mesto filters on the search correct?

What you can do is to write some jQuery to see which value is selected on the first filter. If it is "cr" then your jQuery will unhide the mesto-cr filter and vice versa.

You should be able to use the .change method on this one.
hidden link

Please let me know if this helps.
Thanks,
Shane

#1499315

Hi Shane,

Yes, basically I just need the user to be able to pick a state and after the selection, I need him to be able to pick a region (or city..) related to the state selection. While I cannot use a relationship filter.

Ok, got it, but if this is the only solution I have no experience with jQuery and I got no more time to even consider to try to learn the basics now.

So I need to hire someone to write the jQuery.

So the last question would be if the person needs to know Toolset? I guess that there is no need to know Toolset , but just making sure.

Thank you

D.

#1501781

Shane
Supporter

Languages: English (English )

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

Hi David,

Sorry for the delay in response.

"So the last question would be if the person needs to know Toolset? I guess that there is no need to know Toolset , but just making sure."

No the developer doesn't need to know toolset because the jQuery would be a standard script that is just picking up what value is selected and displaying a hidden field.

It should be noted that we have a few developers registered with us to help out with projects like these that need custom coding.
https://toolset.com/contractors/

Thanks,
Shane