Forums Forums Search & Filter Pro Ajax is clearing added classes (after sf:ajaxfinish)

Viewing 10 posts - 1 through 10 (of 16 total)
  • Trevor
    #242842
    This reply has been marked as private.
    Anonymous
    #242870
    This reply has been marked as private.
    Trevor
    #242962

    If you have Auto Count enabled, you will also need to use the sf:ajaxformfinish action. Maybe that is it?

    Anonymous
    #242969

    Hello Trevor,

    Thanks for your response. I forgot to mention I’m using the sf:ajaxformfinish action as well. It still doesn’t work though.

    Trevor
    #242980

    Are you able to send me a live link/URL to your search page so I can take a look?

    Can you talk me through actions I need to take to see the issue?

    Anonymous
    #242988
    This reply has been marked as private.
    Trevor
    #243036

    Interesting. Using the toggle option might actually cause it to be removed. Do you need to add a switch to it:

    $(this).parent("li").toggleClass('open',1);

    Leaves it ON?

    You may need some logic to test the state of the parent (selected or not).

    Anonymous
    #243109
    This reply has been marked as private.
    Trevor
    #243112
    This reply has been marked as private.
    Ross Moderator
    #243114

    Hi Bond

    If I’m following correctly I see the error.

    The approach your opening post I think was pretty close but there needs to be some additional logic.

    Essentially from this code:

    $(document).ready(function(){
    	$('.searchandfilter ul li li.sf-level-0 > input').click(function(){
    		$(this).parent("li").toggleClass('open');	
    	});
    });
    
    jQuery(document).on("sf:ajaxfinish", ".searchandfilter", function(){
    	console.log("ajax finish");
    	$('.searchandfilter ul li li.sf-level-0 > input').click(function(){
    		$(this).parent("li").toggleClass('open');	
    	});
    });

    You attach the events correctly, which basically says when there is a click, toggle class “open”.

    However, when sf:ajaxfinish completes, the “open” class is removed, this is standard behaviour as our ajax request won’t contain the class you added.

    In sf:ajaxfinish, you do correctly setup the click event again, but you also need to restore the “open” class to whatever it was on first.

    So when you click an item, you can record the class of the element in variable, eg .level-0 .sf-item-41 and then on sf:ajaxfinish, attach the “open” class to that item, before doing anything else like adding the click handler again.

    Does that make sense?

    Thanks

Viewing 10 posts - 1 through 10 (of 16 total)