Search code examples
javascriptjsfprimefacesjsf-2

How to Define 'onSlide' Callback Function of Primefaces Slider Component?


I have a primefaces slider component

<h:inputHidden id="animhidden"/>
<p:slider widgetVar="animslide" onSlide="slideAnimation()" for="animhidden" />

I define slideAnimation function, it is being called when I move the slider. But when I get the current value with PF('animslide').getValue() or $('#animhidden').val(), they get the previous value, not the new value of the slider.

So, How should I define slideAnimation function and get the new value of the slider wiht javascript?


Solution

  • In the primefaces documentation onSlideEnd function is defined as below. I tried the same for onSlide function it worked. Here is the way for the people who is searching for the same issue:

    <p:slider widgetVar="animslide" onSlide="slideAnimation(event, ui)" for="animhidden" />
    
    function slideAnimation(event, ui) {
                console.log(ui.value);
    }
    

    You can also set value with -> PF('animslide').setValue(value)