question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Slider not set correctly when updating value.

See original GitHub issue

Based on Slider with dates example in the docs, if I try to move from date range index manually, even though index and value match to one of the values in the date range it doesn’t update correctly. I’ve already tried to use setTimeout approach and manualRefresh.emit() one too. The only way I’ve seen it actually update the value correctly is by toggling it with an *ngIf, which causes the illusion of blinking and it’s not desirable.

Here’s my code:

setUpDates() {
    this.dateRange = this.createRange();
    this.minValue = this.dateRange[15].getTime();
    this.currentTickIndex = 15;
    // this.maxValue = this.dateRange[29].getTime();
    this.options = {
      stepsArray: this.dateRange.map((date: any) => {
        return { value: new Date(date).getTime() };
      }),
      translate: (value: number): string => new Date(value)
        .toLocaleTimeString('en-GB', { hour12: true, hour: '2-digit', minute: '2-digit' })
    };
  }

createRange(): Date[] {
    const dates: Date[] = [];
    const start = moment(this.date).add(-15, 'minutes');
    for (let i = 0; i <= 30; i++) {
      dates.push(new Date(start.year(), start.month(), start.day(), start.hours(), start.minutes() + i));
    }
    return dates;
  } 

onChange(e: any) {
    this.currentTickIndex = this.options.stepsArray.findIndex(item => item.value === e.value);
  }

moveTick(index) {
    this.currentTickIndex += index;
    if (this.currentTickIndex < 0) {
      this.currentTickIndex = 0;
    } else if (this.currentTickIndex > 30) {
      this.currentTickIndex = 30;
    }
    // this.minValue = this.dateRange[this.currentTickIndex].getTime();
    this.minValue = this.options.stepsArray[this.currentTickIndex].value;
    // this.hideSlider = true;
    setTimeout( () => {
      this.options = Object.assign({}, this.options);
      this.manualRefresh.emit();
    });
    // this.hideSlider = false;
  }

Any hint would be very appreciated. Thanks in advance.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hackermanmxcommented, Dec 20, 2018

It worked! Thanks a lot!

1reaction
piotrdzcommented, Dec 20, 2018

What is the version of slider that you are using? I just fixed a similar issue #52 in v1.1.11.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Slider not set correctly when updating value. · Issue #53 - GitHub
I've already tried to use setTimeout approach and manualRefresh.emit() one too. The only way I've seen it actually update the value correctly is ......
Read more >
jquery - Slider won't update properly - Stack Overflow
I am using the JQuery slider UI Widget. I am getting weird problems when using two sliders in the same form. I tried...
Read more >
UI Slider does not update when value is loaded - Unity Forum
So currently I have an options menu that updates the volume when the slider is changed. I am able to save the volume...
Read more >
InputSlider not updating on binding change
Hi,. I'm having issue with the MDBInputRange component. Expected behavior Updating the slider value through updating the slider property value.
Read more >
Solved: Range control in gallery not updating
Solved: Hey there, I've added a range control to a gallery template to allow the user to change a certain value of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found