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.
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.
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.
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.
(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.
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.
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.
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 ?