View Full Version : Spinner auto-fix onBlur

9 Sep 2009, 9:33 PM
Hey guys,

With the ExtJS 2.0 Spinner field user extension I had posted an override to it, so that upon blur, if the value of the spinner was outside the specified range for that spinner field it would automatically change the value to the correct range limit value.

With the ExtJS 3.0 SpinnerField, it now is even easier to perform the auto-fix and it doesn't have to be done on blur anymore either, since I have updated it to react with the standard "validator" function.

The reason behind this is that for both 2.0 and 3.0 out-of-the-box code, the field allows entering numbers out of range and just marks them invalid, so if you are fine with that and don't want an auto-fixing spinner field, then don't use the following code.

Ext.override(Ext.form.SpinnerField, {
validator: function()
var value = this.getValue()

if (value != this.spinner.fixBoundries(value))
this.spinner.spin.call(this.spinner, null, false);

return true;

Obviously, you'll notice that this will render the field ALWAYS valid with "return true," but this is necessary since this function will validate the field for them automatically, assuming that if they choose a number out of range, they are willing to accept the min or max of the range, depending on which extreme they entered. Also, this will cause ALL SpinnerField instances to have this functionality, which is appropriate for my application, but if not for yours, then just take the validator function out and apply it only to those SpinnerField instances' validator's for which you would like this functionality.

Only tested on FF3.5.2.