I am experiencing the same thing as Charles in this topic at the bottom:
https://toolset.com/forums/topic/drop-down-menu/#post-377826
When using jQuery to pre-fill the State / City's Parent, the City dropdown remains disabled until you user the state drop-down again. In my case, it is for provinces in Canada. I am auto detecting the location province and pre-filling the state filter with the same jQuery example used above.
How can the city drop-down be re-populated with appropriate results?
I am using the real-estate reference site
jQuery(document).ready(function($) {
jQuery("select[name^='wpv-relationship-filter'] option[value='301']").attr("selected","selected");
if (jQuery('#temporary').value = 'Québec') { jQuery("select[name^='wpv-relationship-filter'] option[value='298']").attr("selected","selected"); }
if (jQuery('#temporary').value = 'Saskatchewan') { jQuery("select[name^='wpv-relationship-filter'] option[value='310']").attr("selected","selected"); }
if (jQuery('#temporary').value = 'British Columbia') { jQuery("select[name^='wpv-relationship-filter'] option[value='428']").attr("selected","selected"); }
if (jQuery('#temporary').value = 'Ontario') { jQuery("select[name^='wpv-relationship-filter'] option[value='310']").attr("selected","selected"); }
if (jQuery('#temporary').value = 'Alberta') { jQuery("select[name^='wpv-relationship-filter'] option[value='453']").attr("selected","selected"); }
});
Hello,
It needs custom codes, you can setup custom JS codes remove the "disabled" attribute from City dropdown, for example:
https://stackoverflow.com/questions/13626517/how-to-remove-disabled-attribute-using-jquery
Even with this, the City field does not show any cities until you select another province, then select the original one again.
It is like it selects the proper item in the drop-down, but it does not update the search results
In the attached image the top example is what happens, even using .prop method instead of .attr
The bottom half of the image is what it does with manual selection
This is expected result, the post relationship filter [wpv-control-post-ancestor] needs to select the options manually, then trigger AJAX requests to update following child selectors.
As a workaround, you can pass URL parameter to the post view, it should be able to preset the default options too, for example:
hidden link
The URL parameter name is the selector HTML name, the URL parameter value is the specific post ID.