Reputation: 2066
I am using the jQuery UI spinner 1.2 from Brant Burnett. I would like to have my spinner have a minimum value of 1 and a maximum value of 10. However, I would like the spinner to default to blank, then go to 1 if the user hits up, or 10 if they hit down. Otherwise the value should be treated as null.
Here's the catch: If I set my "min" value to 0, I get the behavior I want. The spinner begins blank. Up brings it to 1 and down brings it to 10. However, if I change that min value from 0 to 1 the spinner always defaults to 1. Even if I try to select the value in the spinner and clear it, it forcibly changes the value back to 1 after the focus is lost on the control.
Does anyone have a reason why this might be? Would a later version correct the issue? Or should I modify the JS file? Thanks!
Upvotes: 1
Views: 1427
Reputation: 2066
I changed line 546 in the jquery.ui.spinner file. Added a condition to also make sure the value is not null before returning the "min" option. This got me the default "blank" behavior I was looking for.
(credit to Brant Burnett, the original author of this plug in: btburnett.com
_validate: function(value) {
var options = this.options,
min = options.min,
max = options.max;
if ((value == null) && !options.allowNull)
value = this.curvalue != null ? this.curvalue : min || max || 0; // must confirm not null in case just initializing and had blank value
if ((max != null) && (value > max))
return max;
else if ((min != null) && (value < min) && (value != null))
return min;
else
return value;
},
Upvotes: 2