Skip Navigation

[Resolved] Pre-fill filter for State or City Parent keeps City field in disabled state

This support ticket is created 5 years, 10 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: Asia/Hong_Kong (GMT+08:00)

Author
Posts
#1229035
toolsetCapture.JPG

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"); }
});
#1229105

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

#1229106
toolsetcapturestate.jpg

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

#1229191

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.