0 Replies Latest reply on Jul 30, 2012 7:22 AM by sergiy.michka

    inputNumberSlider __setValue bug if value is out of range

    sergiy.michka

      Hi,

       

      I think, I've discovered a bug:

      1) put a rich:inputNumberSlider with range of 0-100.

      2) enter -1

      3) value will be changed to 0 -> ok

      4) enter -1 again

      5) value will not change -> bug

       

      From: https://source.jboss.org/browse/RichFaces/trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inputNumberSlider.js?hb=true

      Starting in line 98:

       

      __setValue: function (value, event, skipOnchange) {

          if (!isNaN(value)) {

              if (value > this.maxValue) {

                  value = this.maxValue;

              } else if (value < this.minValue) {

                  value = this.minValue;

              }

              if (value != this.value) {

                  this.input.val(value);

                  var left = 100 * (value - this.minValue) / this.range;

                  this.handleContainer.css("padding-left", left + "%");

                  this.tooltip.text(value);

                  this.tooltip.setPosition(this.handle,{from: 'LT', offset: [0, 5]}); //TODO Seems offset doesn't work now.

                  this.value = value;

                  if (this.onchange && !skipOnchange) {

                      this.onchange.call(this.element[0], event);

                  }

              }

          }

      },

       

       

      First, there are 2 checks, whether the value is within the range and if not the value will be changed to min/max.

      Then, there is a "if (value != this.value)" check, which is allways false in step #4, because the value was changed in range-check previously, thus there is no real change -> bug.

       

      Simple solution would be to remove "if (value != this.value)" and do set the value allways.

      Better one: do the comparasion with old value first, then if value is != old value, do the range check and only as last one apply the actual value-change.

       

      Bug can be seen here (version v.4.2.2.Final): http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=inputNumberSlider&skin=blueSky

      Correct behaviour can be seen here (version 3.3.3): http://livedemo.exadel.com/richfaces-demo/richfaces/inputNumberSlider.jsf?c=inputNumberSlider

       

      Can be reproduced in version 4.2.0 also.

       

      Thanks,

      Sergiy

       

       

      EDIT:

       

      I've changed localy the inputNumberSlider.js from the richfaces-components-ui-4.2.0.Final.jar to following:

      __setValue: function (value, event, skipOnchange) {

          if (!isNaN(value)) {

              if (value != this.value) {

                   if (value > this.maxValue) {

                       value = this.maxValue;

                   } else if (value < this.minValue) {

                       value = this.minValue;

                   }

                  this.input.val(value);

                  var left = 100 * (value - this.minValue) / this.range;

                  this.handleContainer.css("padding-left", left + "%");

                  this.tooltip.text(value);

                  this.tooltip.setPosition(this.handle,{from: 'LT', offset: [0, 5]}); //TODO Seems offset doesn't work now.

                  this.value = value;

                  if (this.onchange && !skipOnchange) {

                      this.onchange.call(this.element[0], event);

                  }

              }

          }

      },

       

      And this bug is fixed with that

       

      EDIT: partially fixed only, we need to do extra check for empty values which automatically resolved to 0, thus it will not work if slider's minValue is set to 0.