andreruffert / rangeslider.js

🎚 HTML5 input range slider element jQuery polyfill
https://rangeslider.js.org
MIT License
2.16k stars 401 forks source link

Impossible to set max='0' #54

Closed gmajoulet closed 10 years ago

gmajoulet commented 10 years ago

It's impossible to set a max to 0 for now

this.max        = parseFloat(this.$element[0].getAttribute('max')) || 100;

0 is false, so it goes to 100 by default.

terehov commented 10 years ago

Hi André,

great library, thanks again! I do have exactly the same issue. My favorite behavior would be: if max = 0 => disable slider.

cheers,

Eugene

gmajoulet commented 10 years ago

https://github.com/andreruffert/rangeslider.js/pull/56

andreruffert commented 10 years ago

I'll look into it. Cheers guys!

andreruffert commented 10 years ago

Would be great if you guys could give me a feedback if the issue is fixed with pr #59. It's already in the develop branch and planed to be in the next release.

gmajoulet commented 10 years ago

No it's not. You're still not checking if the value is false OR 0 (which is false too). So if it's 0, it goes to the fallback 100.

andreruffert commented 10 years ago

e.g. this.$element[0].getAttribute('max') etc. is not a number. So if the attribute is set, it will always use the value if not it is nulland will use the fallback.

gmajoulet commented 10 years ago

No... http://jsfiddle.net/3ussf/

Like I said, 0 is falsy in JavaScript.

Anyway, I need to set max to 0, so I'll keep using my patched version.

andreruffert commented 10 years ago

You are totally right the number 0 is falsy in JS. The point is that element.getAttribute('attr') will return a string and a string isn't false right!? After I got the right value from the attr (min, max, whatever...) it will be converted into a floating point number to be able to calculate with it.

e.g. this.max = parseFloat(this.$element[0].getAttribute('max') || 100)

this.$element[0].getAttribute('max') if there is a attribute max it is a string and never false. this.$element[0].getAttribute('max') will be null if there is no attribute max in this case this.max will be 100 instead.