This project is archived and is in readonly mode.

#430 ✓resolved
Enrique Erne

Slider fires twices on initialization

Reported by Enrique Erne | November 1st, 2010 @ 11:13 PM | in

Added a test that is displaying the slider events (onTick, onChange, onComplete).

Currently (since :setRange was added) Slider fires twice on init. It should only fire only once! I'm not sure how to fix this.

setRange should set the knob to the actual position. Only not the first time (on init) and it does it wrong anyways, I assume since not everything is porperly initialized.

Comments and changes to this ticket

  • Arian

    Arian November 2nd, 2010 @ 09:20 PM

    • State changed from “new” to “open”
    • Milestone set to
    • Assigned user set to “Arian”
    • Milestone order changed from “197539” to “0”
  • Arian

    Arian November 5th, 2010 @ 11:31 PM

    • Milestone order changed from “15” to “0”

    A fix by Jacob:
    eerne, can you verify if it works?

    I think this issue is introduced by
    I don't really see what that commit fixes though at the moment.

  • JacobThornton

    JacobThornton November 6th, 2010 @ 12:01 AM

    My test was essentially copy pasted from eerne's test, then cleaned up a little to make it more direct in regard to how many events have been fired -- so hopefully things are good for him :)

    I don't think my commit reverts aarons commit (or atleast not the test coverage he introduced with his patch) -- he was changing an issue around the absence of pos where my change is addressing an issue with the absence of range...

    The bug appears because "set" is being called twice on initialize (because of setRange). That said "set" has always been present in setRange, so i don't think it was introduced by aaron.

  • Enrique Erne

    Enrique Erne November 6th, 2010 @ 12:19 AM

    Fix and test look great!

  • Aaron Newton

    Aaron Newton November 10th, 2010 @ 07:39 PM

    • State changed from “open” to “resolved”
    • Milestone order changed from “17” to “0”

    per my comment on the pull request:

    I think this should be fine. My only comment is that this change could in theory be tested in specs rather than the ui test. I'm content not to require the extra work to pull it, so I'll do so. Jacob, if you feel like converting it to a specs test just make a new pull request for that work.

  • stephen l

    stephen l March 30th, 2011 @ 03:44 AM

    • Milestone order changed from “12” to “0”

    Hi, sorry for dual post (.core), i'm new here and a bit lost.

    Sliders events should not be triggered at init time, but only when user does realy use them. setRange, set(level) should not trigger events at all. (1.2.44+)
    (think using sliders as control for light power at home and get at least 2 events fired when page load with max and min range values)

    Slider.implement({                                   // prevent fire onChange and onTick events at init time, on set and on setRange
        setWithoutEvent:function(step){                 // set without event
            if (!((this.range > 0) ^ (step < this.min))) step = this.min;
            if (!((this.range > 0) ^ (step > this.max))) step = this.max;
            this.step = Math.round(step);
            return this;
        setWithEvent: function(step){                   // original set with event
                .fireEvent('tick', this.toPosition(this.step));
            return this;
        set: function(step){                            // replace original set
                .previousChange = this.step;
            return this;
        scrolledElement: function(event){               // replace original scrolledElement
            var mode = (this.options.mode == 'horizontal') ? (event.wheel < 0) : (event.wheel > 0);
            this.setWithEvent(this.step + (mode ? -1 : 1) * this.stepSize);

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The MooTools Extensions

People watching this ticket