Skip Navigation

[Resolved] Price range slider stops working after loading search results

This support ticket is created 6 years, 11 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Christian Cox 6 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#597393

Hi,

I continue in previous thread (https://toolset.com/forums/topic/price-range-slider-and-fields/), but a new problem arised, so I created this post.

The Custom search is here: hidden link
The Slider I am using: hidden link

I have a price range slider, which works correctly when I first load the page. After changing the price on slider or anything from searching parameters, the new search results will show, but the slider will not work. With Luo´s help I repaired disappearing the slider after searching, but I don´t know how to make it 100% functional (when I move with the slider, the prices do not update).

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function(slideEvt5) {
  	$("#cenovy-rozsah").slider();
});
#597479

You must re-initialize the slider, as well as the slider event handlers, after the results are updated. I would create a reusable function for this:

function initSlider() {
$("#cenovy-rozsah").slider();
$("#cenovy-rozsah").on("slide", function(slideEvt) {
	$("#hodnota-slideru-min").text(slideEvt.value[0]);
});

$("#cenovy-rozsah").on("slide", function(slideEvt2) {
	$("#hodnota-slideru-max").text(slideEvt2.value[1]);
});

$("#cenovy-rozsah").on("slideStop", function(slideEvt3) {
	jQuery('.js-wpv-filter-trigger').first().trigger('change');  // trigger ajax update
});

$("#cenovy-rozsah").on("slide", function(slideEvt4) {
	$('input[name="wpv-wpcf-cena-min"]').val(slideEvt4.value[0]);
    $('input[name="wpv-wpcf-cena-max"]').val(slideEvt4.value[1]);
});
}

// initialize on first page load
initSlider();

// initialize again after results are updated
$( document ).on( 'js_event_wpv_parametric_search_results_updated', initSlider);
#597501

Hi, thank you for changing the code, the slider works after updating the search results now. But it´s not working 100%. I found out that this function will set the numbers (i.e. 500 and 1000) for slider after update:

$("#cenovy-rozsah").slider('setValue', [500,1000]);

But I don´t know how to get the wpv-wpcf-cena-min and wpv-wpcf-cena-max prices back into the slider instead of the given [500,1000].

#597760

Use jQuery.val() to access the numbers in the min and max inputs:

var min = $('input[name="wpv-wpcf-cena-min"]').val();

Then pass the min and max variables into your slider setValue function instead of 500,1000.

hidden link

#597827

Thanks for the link. I still have some problem with it. At first I had to convert variable string into integer. But I don´t know why the code works fine only for max amount, not for min amount (it gives me NaN output):

function initSlider() {
$("#cenovy-rozsah").slider();
  var minbefore = $('input[name="wpv-wpcf-cena-min"]').val();
  var min = parseInt(minbefore);
  var maxbefore = $('input[name="wpv-wpcf-cena-max"]').val();
  var max = parseInt(maxbefore);
$("#cenovy-rozsah").slider('setValue', [min,max]);
$("#cenovy-rozsah").on("slide", function(slideEvt) {
    $("#hodnota-slideru-min").text(slideEvt.value[0]);
});
 
$("#cenovy-rozsah").on("slide", function(slideEvt2) {
    $("#hodnota-slideru-max").text(slideEvt2.value[1]);
});
 
$("#cenovy-rozsah").on("slideStop", function(slideEvt3) {
    jQuery('.js-wpv-filter-trigger').first().trigger('change');  // trigger ajax update
});
 
$("#cenovy-rozsah").on("slide", function(slideEvt4) {
    $('input[name="wpv-wpcf-cena-min"]').val(slideEvt4.value[0]);
    $('input[name="wpv-wpcf-cena-max"]').val(slideEvt4.value[1]);
});
}
 
// initialize on first page load
initSlider();
 
// initialize again after results are updated
$( document ).on( 'js_event_wpv_parametric_search_results_updated', initSlider);

For example if I write number instead of min variable

$("#cenovy-rozsah").slider('setValue', [0,max]);

the slider works well.

#597863

If you try to parseInt an empty string, the results is NaN:

parseInt(''); // Nan

So you're probably trying to parseInt an empty value. Return 0 instead of parseInt(minbefore) in this case.

var min = minbefore == '' ? 0 : parseInt( minbefore );