Forums › Forums › Search & Filter Pro › Ajax conflict? Filters don't work after first Ajax reload
- This topic has 4 replies, 2 voices, and was last updated 7 years, 1 month ago by
Ross.
-
Anonymous(Private) March 11, 2018 at 6:10 am #165312
http://wordpress-126708-362887.cloudwaysapps.com/search/
I’ve wrapped some of the search filters inside of a “more filter” accordion toggle so that
they can be expanded and collapsed (show / hide filters). When the page is first loaded, these filters work fine. But the very first time the form updates via Ajax, the filters freeze.This doesn’t happen if they’re not wrapped in the accordion, so it seems to be some kind of jQuery / ajax update conflict? Thanks in advance for taking a look.
Here’s the jQuery that’s creating the accordion:
<script type="text/javascript"> jQuery(document).ready(function($) { $('.sf-field-taxonomy-access_level, .sf-field-taxonomy-topic, .sf-field-post_type, .sf-field-post_date').wrapAll('<div class="accordionCollapse clearfix" />'); $('.accordionCollapse').hide(); $('.accordionCollapse').before('<p class="moreFilters">More Filters</p>'); $( '.moreFilters' ).click(function() { $(this).toggleClass( "minus" ); $( '.accordionCollapse' ).slideToggle( "fast" ); }); }); </script>
Ross Moderator(Private) March 11, 2018 at 7:19 pm #165355Hi Kendra
I think its the “wrapAll” function.
You are wrapping
.sf-field-taxonomy-access_level
for example in adiv
, but this is anli
, so this is breaking the DOM structure for theul
I’m not sure exactly what to suggest, but rather than create new elements (like wrapping in a
DIV
) why not just add theclearfix
andaccordionCollapse
classes to our LI’s?There are a couple of prefered methods to attaching classes to S&F (if wanting to use ajax), which I can explain if you are happy to go down that road?
Thanks
Anonymous(Private) March 12, 2018 at 4:18 am #165431Heya, just tried to make that change, and that definitely fixes the “freezing” problem (thank you!) but the CSS classes I add to the
<li>
are removed on ajax update. There something I can do about that?<script type=”text/javascript”>
jQuery(document).ready(function($) {
$(‘.sf-field-search’).after(‘<p class=”moreFilters”>More Filters</p>’);
$(‘.sf-field-taxonomy-access_level, .sf-field-taxonomy-topic, .sf-field-post_type, .sf-field-post_date’).addClass(“accordionCollapse”);
$(‘.accordionCollapse’).hide();
$( ‘.moreFilters’ ).click(function() {
$(this).toggleClass( “minus” );
$( ‘.accordionCollapse’ ).slideToggle( “fast” );});
});</script>
Ross Moderator(Private) March 12, 2018 at 12:50 pm #165509Hi Kendra
The best way to do this for now is with JavaScript – then after S&F loads results via ajax (it also loads a new copy of the search form) you would re-attach your classes – check the first FAQ for the JS event for detecting ajaxfinish:
https://www.designsandcode.com/wordpress-plugins/search-filter-pro/faqs/Let me know if that makes sense.
Thanks
-
AuthorPosts