Skip Navigation

[Resolved] Images disapear when clicking on All filter

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to use images as radio button with view's filter

Solution:
View's offers AJAX filter callback events which you may use as callback to call your required custom JS.

When you visit view's Filter section's JS box - you will see a button "Frontend Events". When you click it it will allow you to choose ajax callback events for parametric search.

Please check following image:
=> https://d7j863fr5jhrr.cloudfront.net/wp-content/uploads/2015/08/views-callback-gui.png

You can find proposed solution with the following reply:
=> https://toolset.com/forums/topic/images-disapear-when-clicking-on-all-filter/#post-617572

Relevant Documentation:

This support ticket is created 6 years, 2 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 10 replies, has 2 voices.

Last updated by nelsonT-2 6 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#616583

Hi,

I'm wonder what is changing in the request when we use a regular filter (i.e. a radio option) vs the default "All" option...

Here's what we are doing: I want to be able to use images in the different filter options.

With some jQuery, I was able to do it and it works fine... When I open the page and click on any option, the filter works well AND the images are always there (using AJAX to refresh the results)... BUT when I click back on ALL, then the images disappear...

Here's my JS code:
jQuery('#filtreRealisations input:checked').parent().addClass('sel');
jQuery(document).ajaxComplete(function(){
jQuery('#filtreRealisations input').parent().removeClass('sel');
jQuery('#filtreRealisations input:checked').parent().addClass('sel');
});

jQuery('#filtreRealisations .radio label').each(function(){
var slug = jQuery(this).find('input').val();
jQuery(this).prepend('<img src="/wp-content/uploads/2018/02/' + slug + '.png">');
});

The first top section is to make sure that the filter is shown as selected... Since it changes on every AJAX request, I've put it outside a function (for when the page loads) and again inside an ajaxComplete event...

The second part is to insert the image... Again, as I said, it works fine until we click the "All" default option (and of course, doesn't bring the images back after)... I tried to put that into an ajaxComplete again, but it outputs the images 2-3 times... and there's probably some ajax always in the background, because it adds some every few seconds...

SO, what's the difference between any option and the default one? What kind of code can I put for my images to stay there no matter the option selected?

Nelson

P.S. The site is not listed in my account, so my client probably used her own account... The page is hidden link (not translated yet)...

#616618

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - View's offers AJAX filter callback events which you may use as callback to call your required custom JS.

When you visit view's Filter section's JS box - you will see a button "Frontend Events". When you click it it will allow you to choose ajax callback events for parametric search.

Please check following image:
=> hidden link

For example:

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
    /**
    * data.view_unique_id (string) The View unique ID hash
    * data.layout (object) The jQuery object for the View layout wrapper
    */
         
YOUR CUSTOM CODE GOES HERE
        
});

Does this help?

#616622

Thank you, but it basically does the same thing as what ajaxComplete does... So, the problem is sill there.

I tried adding a code to delete the image and it does work when I click on the "All" option, but when I click any of the other options, it still doubles every image...

I even added a code to delete all the images before adding it again, and the result is the same...

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
/**
* data.view_unique_id (string) The View unique ID hash
* data.layout (object) The jQuery object for the View layout wrapper
*/
jQuery('#filtreRealisations .radio label').each(function(){
jQuery('#filtreRealisations .radio label').remove('img');
var slug = jQuery(this).find('input').val();
jQuery(this).prepend('<img src="/wp-content/uploads/2018/02/' + slug + '.png">');
});
});

I also had to keep the inside code one in order for the images to appear when we first load the page...

#616626

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please share exact problem URL where I can see the behavior you shared?

Also, please share all required details, which view you are using.

Also, few screenshots will be helpful to understand what is your issue and what should be the expected results.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

Please note that - this is custom jQuery code, I'll try to check and try to guide you with solution but there is no promise on that as this is custom code and it's beyond the scope of our support policy.

#616708

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - we do not recommend to do any debug on live site.

Could you please create 1:1 copy of your live site as a test site and send me access details.

I have set the next reply to private which means only you and I have access to it.

#617331

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now.

I've adjusted your custom Javascript code as given under and I see the filter items are not duplicated now.

jQuery(document).ready(function($){

jQuery('#filtreRealisations input:checked').parent().addClass('sel');
  
/*
jQuery(document).ajaxComplete(function(){
  jQuery('#filtreRealisations input').parent().removeClass('sel');
  jQuery('#filtreRealisations input:checked').parent().addClass('sel');
});
*/

jQuery('#filtreRealisations .radio label').each(function(){
  jQuery('#filtreRealisations .radio label').remove('img');
  var slug = jQuery(this).find('input').val();
  jQuery(this).prepend('<img src="/wp-content/uploads/2018/02/' + slug + '.png">');
});


});


jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
	/**
	* data.view_unique_id (string) The View unique ID hash
	* data.layout (object) The jQuery object for the View layout wrapper
	*/
  
   jQuery('#filtreRealisations input').parent().removeClass('sel');
   jQuery('#filtreRealisations input:checked').parent().addClass('sel');
  
 /* jQuery('#filtreRealisations .radio label').each(function(){
    jQuery('#filtreRealisations .radio label').remove('img');
    var slug = jQuery(this).find('input').val();
    jQuery(this).prepend('<img src="/wp-content/uploads/2018/02/' + slug + '.png">');
  });
  */
});
#617379

But, we are back to square #1: the images disappear when we click on "TOUT" (or "ALL")...

#617572

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added following event as well to your view's JS box:

jQuery( document ).on( 'js_event_wpv_parametric_search_form_updated', function( event, data ) {
	/**
	* data.view_unique_id (string) The View unique ID hash
	* data.view_changed_form (object) The jQuery object for the View form after being updated
	* data.view_changed_form_additional_forms_only (object) The jQuery object containing additional forms from other instances of the same View inserted using the [wpv-form-view] shortcode
	* data.view_changed_form_additional_forms_full (object) The jQuery object containing additional forms from other instances of the same View inserted using the [wpv-view] shortcode
	*/
  jQuery('#filtreRealisations .radio label').each(function(){
  jQuery('#filtreRealisations .radio label').remove('img');
  var slug = jQuery(this).find('input').val();
  jQuery(this).prepend('<img src="/wp-content/uploads/2018/02/' + slug + '.png">');
});

And I can see that now it's working even if you click on "TOUT" (or "ALL").

#617605

Thank you for trying...

Are you working on hidden link ?

Because I don't know why, but on my end I don't see the same thing as you do: not only does the images disappear when I click on "TOUT" (after selecting one of the filters), but now the selected element doesn't get highlighted anymore (it was previously)...

Just to make sure we are talking about the same thing: I'm not talking about the images in the white area (i.e. the results), but in the red area (i.e. the filters)...

I'm on Chrome on PC.

Nelson

#617648

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - I'm working on your staging site:

If you will check your view's JS box - You will see the code I've added:
=> hidden link

You should try to delete your browser cache or try with another browser and check if that help to resolve your issue. I've tested this on Chrome and FireFox and its working fine.

#617653

Ok, it works in Firefox... Chrome gives me strange behavior sometimes...

Thanks a lot for all your help! You were wonderful!

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