Skip Navigation

[Resolved] Reset second search filter on first filter change

This support ticket is created 4 years, 3 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.

Our next available supporter will start replying to tickets in about 1.23 hours from now. 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 9 replies, has 2 voices.

Last updated by umbertoZ 4 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#1729625

Hi, I've a View with 2 filters and "Show only filter options that would produce results" selected.

I've noticed that on Blocks I cannot change the "Choose if you want to hide or disable irrelevant options for inputs:" option, I can only hide the irrelevant options. I can do it with Views, but I miss this option on Blocks.

This is what I'm trying to do:

1. I'd like to always display all the options on the first filter and they should be active. Can I do it with some custom code?

2. I'd like to reset the second filter every time I chage the first filter value (so the second should display the default placeholder). Is it possible?

cheers

#1730339

Hi,

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

Your observation is correct and in Blocks based views, it is not possible to disable irrelevant search filter options and they can only be hidden. I'm going to share this feedback internally to the concerned team.

1. I'd like to always display all the options on the first filter and they should be active. Can I do it with some custom code?

- The "Show only filter options that would produce results" in Blocks view works for all the search filters and I'm afraid, it can't be made to restrict to particular fields.

2. I'd like to reset the second filter every time I chage the first filter value (so the second should display the default placeholder). Is it possible?

- This is possible using Javascript/jQuery and you can structure your custom function for this in a way that it ininitialize it with "js_event_wpv_pagination_completed", "js_event_wpv_parametric_search_results_updated" and "ready" events.
( this is needed if the view is set to update results using AJAX, so that our custom script can initialize on the completion of pagination, search and page load operations )

Example:


jQuery( document ).on( 'js_event_wpv_pagination_completed js_event_wpv_parametric_search_results_updated ready', function( event, data ) {

// actual script to change the value of one input field based on the change in another
 
});

-I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1730673

Hi Waqar, thanks for your answer. Can you give me an example of Javascript/jQuery to reset the second filter every time I chage the first filter value? I tried this:

var dockOld = '';
var dockNew = '';
var dockChange = 'False';

jQuery(document).ready(function($) {
  jQuery('[name=wpv-wpcf-stand]').attr('disabled', 'disabled');
  jQuery('[name=wpv-wpcf-dock] option').removeAttr('disabled');
});

function dockSelectChange() {
  jQuery('[name=wpv-wpcf-dock]').on('focus', function () {
    dockOld = this.value;
  }).change(function() {   
    dockNew = jQuery('[name=wpv-wpcf-dock]').val(); 
    dockChange = 'True';

    console.log('dockOld: '+dockOld); 
    console.log('dockNew: '+dockNew); 
    console.log('dockChange: '+dockChange); 

  });
}

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {

  dockSelectChange();  
  jQuery('[name=wpv-wpcf-dock] option').removeAttr('disabled');

  console.log('--if--');

  if (dockChange == 'True') {
    if (dockOld != dockNew) {
      if (dockNew == 0) {
        console.log('dockNew == 0'); 
        jQuery('[name=wpv-wpcf-stand] option').removeAttr('selected');
        jQuery('[name=wpv-wpcf-stand]').attr('disabled', 'disabled').val('');
      } else {
        console.log('dockOld != dockNew'); 
        jQuery('[name=wpv-wpcf-stand] option').removeAttr('selected');
        jQuery('[name=wpv-wpcf-stand]').removeAttr('disabled').val(''); 
      }
    }  
    dockChange = 'False';
  }

});

It works fine on the select, but it doesn't reset the search and it doesn't remove the current 2nd filter option if the result is empty (depending on the new 1st filter option).

can you help me?

#1732939

Thanks for writing back.

I'll be happy to take a look and share an example if you could send the link to a page with this view.

#1734229

Hi Waqar, this is the example:

hidden link

cheers

#1735735

Hi,

Thank you for sharing the link.

I've tested the search form on this page and noticed that the second filter ( wpv-wpcf-stand ), gets reset every time the first filter ( wpv-wpcf-dock ) is changed.

Looks like you've managed to make this work after writing to us, but in case it still doesn't work for any particular case, please do let me know about the exact steps.

regards,
Waqar

#1736515
test2.png

Hi Waqar, it works fine but it doesn't reset the search and it doesn't remove the current 2nd filter option if the result is empty.

For example, if I select:

1st select location - the first option "Agua Amarga"
2nd select type - the first option "Casa completa"

then I change to:
1st select location - the second option "Boca de los Frailes"

my JS reset the second filter, but I get no result because it is still filering by "Casa completa". I also still find "Casa completa" on the 2nd filter even if there aren't any result in "Agua Amarga" (I attach a screenshot).

#1737433

Hi,

Thank you for the screenshot and I understand what you're referring to.

Can you please also share temporary admin login details, so that I can troubleshoot this after looking into the data and view's filter in the backend?

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1738271

Hi,

Thank you for sharing the admin access.

Can you please replace your custom script with:


jQuery( document ).on( 'js_event_wpv_pagination_completed js_event_wpv_parametric_search_results_updated ready', function( event, data ) {

	jQuery('select[name=wpv-wpcf-dock] option').removeAttr('disabled');

	var wpcfDock = jQuery('select[name="wpv-wpcf-dock"]').val();

	if (wpcfDock == '0') {
		jQuery('[name=wpv-wpcf-stand]').attr('disabled', 'disabled');
	}

	jQuery('select[name="wpv-wpcf-dock"]').on('change', function() {
		jQuery('select[name="wpv-wpcf-stand"]').val(0);
	});

});

This should do the trick.

regards,
Waqar

#1739735

Hi, it works fine, I've just added this to disable the 2nd filter on first page load:

jQuery(document).ready(function($) {
  jQuery('[name=wpv-wpcf-stand]').attr('disabled', 'disabled');
});

My issue is resolved now. Thank you!