onSlideEnd component return the previous value, not the selected ones in range mode #274
-
It seems that when calling onSlideEnd in a slider, it returns the value where the slider started, not where it ends. I'm assuming that's not what is expected, since I'm personally always more interest in the current values than the starting ones. If this is the intentional behavior, what is the best practice to get the current values via the onSlideEnd function? Edit: I should specify. I'm observing this behavior in PrimeReact 9.6.1 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hi, I could not reproduce this issue with PrimeNG 16.5.1, neither with the
See the browser console (F12 - Console) output, if I move the slider in either of these examples, the Which PrimeNG version are you using and could you possibly share a StackBlitz example with your code? As a workaround you could directly access the values if you add a template reference to the slider, let's say <p-slider
#yourSlider
[(ngModel)]="rangeValues"
[range]="true"
(onChange)="change($event)"
(onSlideEnd)="end($event)"
styleClass="w-20rem"
></p-slider> and access the slider using @ViewChild('yourSlider')
private yourSlider!: Slider; Then you could access the value as follows, but this is not recommended from my side, as you should already get the correct values from the end(event: SliderSlideEndEvent): void {
console.log('End from Event', event.values); // Value from the event binding emitter
console.log('End from the Slider instance', this.yourSlider.values);
} As a side note, this discussion should be moved to the PrimeNG category as it does not have anything to do with PrimeFlex. P.S. @cetincakiroglu I had to add |
Beta Was this translation helpful? Give feedback.
-
I ended up using the onSlideEnd function in a useEffect to work around the issue:
The callback function uses the sliderValues in the way that I was intending to use the return values of the onSlideEnd return value. So, not entirely elegant, but it works. |
Beta Was this translation helpful? Give feedback.
-
@melloware ah, you are correct. As part of my workaround I forgot to undo something to make it work. Apologies. |
Beta Was this translation helpful? Give feedback.
@ftimurs it was fixed in 9.6.2.: primefaces/primereact#4680