Spinner Widgetversion added: 1.9
Description: Enhance a text input for entering numeric values, with up/down buttons and arrow key handling.
Options
cultureType: String
null
null, the currently set culture in Globalize is used, see Globalize docs for available cultures. Only relevant if the numberFormat option is set. Requires Globalize to be included.disabledType: Boolean
false
true.Initialize the spinner with the disabled option specified:
$( ".selector" ).spinner({ disabled: true }); |
Get or set the disabled option, after initialization:
// gettervar disabled = $( ".selector" ).spinner( "option", "disabled" );// setter$( ".selector" ).spinner( "option", "disabled", true ); |
iconsType: Object
{ down: "ui-icon-triangle-1-s", up: "ui-icon-triangle-1-n" }
- up (string, default: "ui-icon-triangle-1-n")
- down (string, default: "ui-icon-triangle-1-s")
incrementalType: Boolean or Function()
true
-
Boolean: When set to
true, the stepping delta will increase when spun incessantly. When set tofalse, all steps are equal (as defined by thestepoption). - Function: Receives one parameter: the number of spins that have occurred. Must return the number of steps that should occur for the current spin.
maxType: Number or String
null
max attribute is used if it exists and the option is not explicitly set. If null, there is no maximum enforced.- Number: The maximum value.
-
String: If Globalize is included, the
maxoption can be passed as a string which will be parsed based on thenumberFormatandcultureoptions; otherwise it will fall back to the nativeparseFloat()method.
minType: Number or String
null
min attribute is used if it exists and the option is not explicitly set. If null, there is no minimum enforced.- Number: The minimum value.
-
String: If Globalize is included, the
minoption can be passed as a string which will be parsed based on thenumberFormatandcultureoptions; otherwise it will fall back to the nativeparseFloat()method.
numberFormatType: String
null
pageType: Number
null
stepType: Number or String
null
stepUp()/stepDown() methods. The element's step attribute is used if it exists and the option is not explicitly set.- Number: The size of the step.
-
String: If Globalize is included, the
stepoption can be passed as a string which will be parsed based on thenumberFormatandcultureoptions, otherwise it will fall back to the nativeparseFloat.
Methods
destroy()
- This method does not accept any arguments.
disable()
- This method does not accept any arguments.
enable()
- This method does not accept any arguments.
option( optionName ) Returns: Object
optionName.-
optionNameType: StringThe name of the option to get.
option() Returns: PlainObject
- This method does not accept any arguments.
option( optionName, value )
optionName.option( options )
-
optionsType: ObjectA map of option-value pairs to set.
stepDown( [steps ] )
If the resulting value is above the max, below the min, or reuslts in a step mismatch, the value will be adjusted to the closest valid value.
-
stepsType: NumberNumber of steps to decrement, defaults to 1.
stepUp( [steps ] )
If the resulting value is above the max, below the min, or reuslts in a step mismatch, the value will be adjusted to the closest valid value.
-
stepsType: NumberNumber of steps to increment, defaults to 1.
value() Returns: Number
numberFormat and culture options.- This method does not accept any arguments.
value( value )
-
valueThe value to set. If passed as a string, the value is parsed based on the
numberFormatandcultureoptions.
widget() Returns: jQuery
jQuery object containing the generated wrapper.
- This method does not accept any arguments.
Events
change( event, ui )
spin( event, ui )
ui.value).
Can be canceled, preventing the value from being updated.
start( event, ui )
Spinner wraps a text input, adds two buttons to increment and decrement the current value, along with handling key events for the same purpose. It delegates to Globalize for number formatting and parsing.
Keyboard interaction
- UP: Increment the value by one step.
- DOWN: Decrement the value by one step.
- PAGE UP: Increment the value by one page.
- PAGE DOWN: Decrement the value by one page.
Focus stays in the text field, even after using the mouse to click one of the spin buttons.
Additional Notes:
- This widget requires some functional CSS, otherwise it won't work. If you build a custom theme, use the widget's specific CSS file as a starting point.
Example:
Plain number spinner
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>spinner demo</title></head><body><input id="spinner"><script>$( "#spinner" ).spinner();</script></body></html> |