Forums › Forums › Search & Filter Pro › Losing CSS after Ajax reload
Tagged: css
- This topic has 7 replies, 2 voices, and was last updated 4 years, 5 months ago by Trevor.
-
Anonymous(Private) July 2, 2020 at 3:37 pm #251182
Hi,
I bought the plugin yesterday and noticed that the CSS is lost when any of filters are clicked. However when I hit refresh on the browser, the CSS comes back. I checked the CSS, the Style2 tags go missing, and they come back when browser is refreshed. This happens on every filter click irrespective of whether it is a Radio Checkbox or Combo.
Could you help me to understand what could be causing this.My setup is as follows:
Woocommerce
Grid modification plugin – None
Location – localhost
Filter defined using Taxonomies
Load results using Ajax? – Checked
Make searches bookmarkable – Checked
Use only Ajax on the results page – Unchecked (Tried also with Checked)
Load JavaScript & CSS files – Checked
Lazy Load JavaScript – Unchecked
Combobox Script – Select2
Load jQuery UI i18n files – Unchecked
Auto submit form – Checked
Enabled Auto Count – Checked
Update the Search Form on user interaction – Checked
Also I rewrote the WordPress Default Search form using this script from the Support Forum
function sandf_change_search_url_rewrite() {
if ( is_search() && ! empty( $_GET[‘s’] ) ) {
wp_redirect( home_url( “products/?_sf_s=” ) . urlencode( get_query_var( ‘s’ ) ) );
exit();
}
}
add_action( ‘template_redirect’, ‘sandf_change_search_url_rewrite’ );Trevor(Private) July 3, 2020 at 11:46 am #251296I suspect that those tags are not being added by our plugin, but instead are being added by one of these:
1. Your theme
2. Another plugin
3. Code you have addedBut, the tags are added at document ready, but the JavaScript that does this does not recognize that our Ajax has fired. The JavaScript that adds the tags needs to be run again at that point, like this:
<script>(function ( $ ) { "use strict"; $(document).on("sf:ajaxfinish", ".searchandfilter", function(){ // call your script or function here }); }(jQuery));</script>
Anonymous(Private) July 3, 2020 at 8:50 pm #251376This didn’t work. I’ve added the script as you suggested in the function.php of my child theme. Any other suggestion?
function enqueue_select2_jquery() {
wp_register_style( ‘select2css’, ‘//cdnjs.cloudflare.com/ajax/libs/select2/3.4.8/select2.css’, false, ‘1.0’, ‘all’ );
wp_register_script( ‘select2’, ‘//cdnjs.cloudflare.com/ajax/libs/select2/3.4.8/select2.js’, array( ‘jquery’ ), ‘1.0’, true );
wp_enqueue_style( ‘select2css’ );
wp_enqueue_script( ‘select2’ );
}
add_action( ‘admin_enqueue_scripts’, ‘enqueue_select2_jquery’ );?>
<script>(function ( $ ) {
“use strict”;
$(document).on(“sf:ajaxfinish”, “.searchandfilter”, function(){
// call your script or function here
$(‘.option-tree-ui-select’).select2();
});
}(jQuery));</script><?php
any other suggestion? Not just
Anonymous(Private) July 3, 2020 at 8:57 pm #251380Not just the Select2 classes are missing but entire spans too.
See this code Before Ajax run and after Ajax run.
https://ibb.co/K2MPSkj
https://ibb.co/GkpXZjzTrevor(Private) July 6, 2020 at 5:00 pm #251583Are you trying to add Select2 on the dropdowns? Such as described here:
https://support.searchandfilter.com/forums/topic/css-dropdown-option-active-hover/#post-249903
-
AuthorPosts