Skip Navigation

[Résolu] Conditionally hiding filters in custom search view

This support ticket is created Il y a 5 années et 3 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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/Karachi (GMT+05:00)

This topic contains 2 réponses, has 2 voix.

Last updated by Stephen Vaughan Il y a 5 années et 3 mois.

Assisted by: Waqar.

Auteur
Publications
#1187650

Hi Nigel and team,

I have tried your suggestion for conditionally hiding filters as per the instructions on this support ticket:

https://toolset.com/forums/topic/conditional-display-of-a-filter-fields/

My prototype is based on a grandparent > parent > child relationship for boroughs of New York, neighbourhoods, properties. I tried initially with your code suggestion, edited to match my types and relationships. On initial page load all is good and when I select a borough the neighbourhood filter appears. But, if I return the borough back to its default select value the neighbourhood filter remains visible.

The result can be tested here:

hidden link

I have modified my javascript to the following to see if that will work.

( function( $ ) {
$( document ).ready( function(){
var boroughSelect = document.getElementById("wpv_control_select_wpv-relationship-filter_borough");
var borough = boroughSelect.options[boroughSelect.selectedIndex].text;
// "Select Borough" is the default in the drop down select

$('.neighbourhood-filter').hide();

$('#wpv_control_select_wpv-relationship-filter_borough').change( function(){
if ( borough != "Select Borough" ){
$('.neighbourhood-filter').show();
} else {
$('.neighbourhood-filter').hide();
}
});
});
})( jQuery );

It seems to respond to the initial borough selection but returning back to the default leaves the Neighbourhoods filter visible. From what I can see the .change() function really does nothing. If I remove it and all the contained code the script still works in the manner I describe above. The view is configured to AJAX results update when visitors change any filter values, so maybe this is not compatible.

I am happy for it to work as is but if it can be made to work, that would be good too.

#1188243

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Stephen,

Thank you for contacting us and I'll be happy to assist.

Since your view is set to update search results using AJAX (i.e. without page reloading), you'll need to make your custom script not only work when the page loads, but also when the results are updated through AJAX.

First, you'll wrap your script inside a named function and load it when the page loads, e.g.:


function custom_filter_processing() {
// code for processing
}
 
jQuery( document ).ready( function( $ ) {
custom_filter_processing();
});

Note: you'll replace "// code for processing" with the actual script to show or hide the filtering fields.

Next, to make this script also execute, when the results have been updated, add the function's name "custom_filter_processing" (without the quotations marks) in the field "will run after updating the results".

You'll see this in the View's "Custom Search Settings", as shown in this example screenshot:
( screenshot: hidden link )

I hope this helps and let me know how it goes.

regards,
Waqar

#1188272

My issue is resolved now. Thank you!

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