Increment / decrease events for dijit.form.NumberSpinner

Is there a way to catch an event if the value inside the dijit.form.NumberSpinner widget increases or decreases?

What I intend to do is when the value drops below 0, set the text inside the NumberSpinner widget to "Never", and when the user increments it from "Never", it should be set to 0 again.

+3
source share
1 answer
dojo.declare("MySpinner", [Spinner], {

    zeroValue: 'Never',

    adjust: function(/*Object*/ val, /*Number*/ delta){
        arguments[0] = val && val > 0 ? val : 0;
        return this.inherited(arguments);
    },

    _getValueAttr: function() {
      var v = this.inherited(arguments);
      return (!v || v <= 0) ? 0 : v;
    },

    format: function(/*Number*/ value, /*dojo.number.__FormatOptions*/ constraints){
      var v = this.inherited(arguments);
      if (v <= 0 || !v) 
         return this.zeroValue;

      return v;
    },

    isValid: function(/*Boolean*/ isFocused){
        var v = this.get('value');
        if (!v) {
            return true;
        }           
        return this.inherited(arguments);
    }
});  

Here is a working example

http://jsfiddle.net/cswing/zDVep/

+3
source

All Articles