Skip Navigation

[Resolved] Need help with search form Conditional Logic(If Country X, Display Cities A & C)

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 – 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)

This topic contains 7 replies, has 2 voices.

Last updated by Shane 3 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#1770847

Tell us what you are trying to do?
Hi,

I have a search form with 4 fields:

Employee Name (text field)
License Number (text field)
Country (dropdown)
City (dropdown)

I wish to apply conditional logic to my search fields and I'm looking for some guidance as to how to do this. How can I set the "City" dropdown to change dynamically based on the "Country" that has been selected? I have entries in the database, so if the website visitor selects "India" from the Country dropdown, the entries in the City dropdown change accordingly to whatever Indian cities are in the data that has been imported.

Separately, some Countries will not have a City, so for example, if I select a country which has no cities in our database, then I would like the City dropdown to disappear, so it's clear for the user to proceed with the search.

Any help would be greatly appreciated.

Thank you

Is there any documentation that you are following? I looked at https://toolset.com/course-lesson/conditional-display-for-form-inputs/. However, I'm not using Toolset Forms. The search form has been created via Views. The code is as follows:

[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="row">
<div class="col-sm-3"><div class="form-group">
<label class="homelabel">[wpml-string context="wpv-views"]Employee Name[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-employee-name" url_param="wpv-wpcf-employee-name"]
</div></div>
<div class="col-sm-3"><div class="form-group"><label class="homelabel">[wpml-string context="wpv-views"]License Number[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-license-number" url_param="wpv-wpcf-license-number"]</div>
</div>
<div class="col-sm-3"><div class="form-group">
<label class="homelabel" for="wpv-wpcf-country">[wpml-string context="wpv-views"]Country[/wpml-string]</label>
[wpv-control-postmeta type="select" field="wpcf-country" default_label="Select Country" url_param="wpv-wpcf-country"]
</div></div>
<div class="col-sm-3"><div class="form-group">
<label class="homelabel">[wpml-string context="wpv-views"]Location[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-county-of-residence" type="select" default_label="Select Location" url_param="wpv-wpcf-county-of-residence"]
</div></div>
</div>
<div class="row">
<div class="col-sm-4">[wpv-filter-submit name="Search" type="button" output="bootstrap" class="fusion-button button-3d fusion-button-round button-large button-custom button-33"] [wpv-filter-reset name="Reset" output="bootstrap" class="fusion-button button-3d fusion-button-round button-large button-custom button-40"] </div>
<div class="col-sm-8"><a href="hidden link"><button type="button" class="fusion-button button-3d fusion-button-round button-large button-custom button-33">View All Registered PSA Employees</button></a></div>
</div>
[/wpv-filter-controls]
[wpv-filter-end]

Is there a similar example that we can see? I can't find any at the moment, but if my overview above doesn't make sense then I can have a look for one.

What is the link to your site? hidden link

#1771109

Shane
Supporter

Languages: English (English )

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

Screenshot 2020-09-09 at 9.26.38 AM.png

Hi John,

Thank you for getting in touch.

Based on the logic here i'm assuming you are using our Classic views. In this case you will need to enable the "Show only available options for each input" setting. This will cause your filters to become dependent on each other.

This can be done under the Custom search settings. See Screenshot

From there you can set the behaviour for each individual input.

If you're not seeing this setting you can enable the "Custom Search Settings" section by scrolling to the top of your view and on the right hand corner you should see a tab called "Screen Options" click this and enable it from here.

Please let me know if this helps.
Thanks,
Shane

#1772689
search.JPG

Hi Shane,

Thank you for your response. Yes I'm using the Classic views. Your feedback has definitely helped and the "City" now appears to be dependent on the "Country", which is what I want. However, there are still some issues:

(1) If I select a Country first, then the City dropdown options change accordingly. However, if I then select one of the associated Cities, after 1 - 2 seconds, it defaults back to the "Select Location" placeholder. I've no idea why it is doing this. Link is hidden link if you want to see what I'm referring to.

(2) Separately, I would like to make the free text search field "Search Location" search for partial locations as opposed to exact strings. So if I search for "Co. Cork" it will return results. But if I search for "Cork" it will not return anything. The code I used is as follows. Screenshot attached.

<div class="form-group">
<label class="homelabel">[wpml-string context="wpv-views"]Search Location[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-county-of-residence" url_param="wpv-wpcf-county-of-residence"]
</div>

(3) How can I hide the "Location" dropdown if "India" has selected? We do not have locations for Indian based employees in the custom fields.

(4) How can I make the Country default to "Republic of Ireland"?

Any help would be greatly appreciated.

Thank you

#1773379

Shane
Supporter

Languages: English (English )

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

Hi John,

(1) If I select a Country first, then the City dropdown options change accordingly. However, if I then select one of the associated Cities, after 1 - 2 seconds, it defaults back to the "Select Location" placeholder. I've no idea why it is doing this. Link is hidden link if you want to see what I'm referring to.

I was able to see the issue. Can you allow me to have admin access to the website so that I can check on this for you ? What is suppose to happen is that after the Location filter refreshes you should be able to select your search attribute without any issues.

I've enabled the private fields for your next response.

(2) Separately, I would like to make the free text search field "Search Location" search for partial locations as opposed to exact strings. So if I search for "Co. Cork" it will return results. But if I search for "Cork" it will not return anything. The code I used is as follows. Screenshot attached.

In order to do this you will need to insert the text search field . The search field should look something like this.
[wpv-filter-search-box output="bootstrap"]

What you are doing now is checking for an exact match with the search location field as it is targeting a specific custom field and its values.

(3) How can I hide the "Location" dropdown if "India" has selected? We do not have locations for Indian based employees in the custom fields.

Not possible to do because our code only hides the values and not the filter itself. If you want to hide the filter completely you will need to use custom code to do it.

(4) How can I make the Country default to "Republic of Ireland"?

I wouldn't recommend setting an actual value as the default but you can do it by using some custom javascript to select the value. This will affect the the value in the Locations filter as it will only show the locations for the Republic of Ireland so users wont be able to choose any other locations unless they change from the Republic of Ireland first.

Thanks,
Shane

#1775169

Hi Shane,

Perhaps don't spend too much time looking at this. Today I created a new search on a separate environment using Toolset Blocks rather than using Views. I'm making good progress, but I've had to create a new ticket (#1775165) as I'm having an issue with the Dropdown in the search.

Feel free to have a look at that ticket instead, if you have time. If not then I'm sure one of your colleagues will pick it up.

Thank you

#1776071

Shane
Supporter

Languages: English (English )

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

Hi John,

Thanks for the updated.

Can you let me know if the same issue still remains on your new view ? Does the Location filter still flash and reset?

Or is this issue resolved.

Please let me know.
Thanks,
Shane

#1776739

Hi Shane,

Unfortunately I'm having issues with the new view where the Location doesn't even change after you change the Country. You will be able to see the conversation on the other thread. I've tried disabling all plugins and changing the theme but the dropdown issues still occurring.

So this is still an issue unfortunately at the moment.

Thanks

#1780487

Shane
Supporter

Languages: English (English )

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

Hi John,

I must apologize for the delay in response as the forums have been quite busy.

We have recently released updates for our Toolset plugins. Can you try updating to the latest versions and let me know if the issue still remains for you ?

Thanks,
Shane

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