Forums › Forums › Search & Filter Pro › Select2 Orderby Not displaying
- This topic has 16 replies, 2 voices, and was last updated 9 years, 4 months ago by
Anonymous.
-
Ross Moderator(Private) May 10, 2016 at 10:53 pm #45234
Hey Andrew
I can’t see the select2 on that page but I may have an idea.
Is this after a search has been performed it loses the select2?
In this case I think if you disable ajax it will work?
I think the issue is, when using ajax, the results are reloaded, but in addition to this the search form is too.
This means a regular select will be loaded in, and you will need to apply your “select2” js to it.
Check the first question here:
http://www.designsandcode.com/wordpress-plugins/search-filter-pro/faqs/
To get our events, so you know when an ajax request has finished and to re-attach select2.
Thanks
Ross Moderator(Private) May 19, 2016 at 1:16 am #45976Hi Andrew
No plugin can remove and add a form element via ajax, and automatically load in custom Javascript your have applied to it.
There is just no way to do it – so its not a plugin limitation more a implementation issue.
Looking at your issue, what I said previously still stands – you need to run select 2 on your form fields after an ajax request has completed.
So, your page will already be loading a version of select2 in the code somewhere – so we do not need to load the whole library again. Instead we just need to call teh same function you probably already called on the fields…
So – it looks like from your case it would be something like:
$(document).on("sf:ajaxfinish", ".searchandfilter", function(){ console.log("ajax complete"); //so load your lightbox or JS scripts here again+ $('.searchandfilter select').select2(); //re-init select2 });
If you open the console, do you see the logs “ajax complete”?
Thanks
Anonymous(Private) May 20, 2016 at 8:55 pm #46210I have found how the theme is adding the select2 to the woocommerce sorting select:
$j(document).ready(function() { "use strict"; $j('.price_slider_wrapper').parents('.widget').addClass('widget_price_filter'); initSelect2(); initAddToCartPlusMinus() }); <strong>function initSelect2() { $j('.woocommerce-ordering .orderby, #calc_shipping_country, #dropdown_product_cat').select2({ minimumResultsForSearch: -1 }); $j('.woocommerce-account .country_select').select2();</strong> }
I tried adding the search and filter select class .searchandfilter .sf-input-select into the function
but unfortunately it didnt work.
I feel this script is close to what I need but I dont know how to combine it with the script you started for me above.Ross Moderator(Private) May 25, 2016 at 11:21 am #46638Hi Andrew
It looks like the code I gave your originally for that should have worked – however, perhaps you didn’t try it inside the ready function, so your
custom_js.js
should be:var $j = jQuery.noConflict(); $j(document).ready(function() { "use strict"; $j(document).on("sf:ajaxfinish", ".searchandfilter", function(){ console.log("ajax complete"); //so load your lightbox or JS scripts here again+ $j('.searchandfilter select').select2(); //re-init select2 }); });
Let me know when you’ve added that and if it works!
Thanks
-
AuthorPosts