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
Default:
null
Sets the culture to use for parsing and formatting the value. If
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.iconsType: Object
Default:
{ down: "ui-icon-triangle-1-s", up: "ui-icon-triangle-1-n" }
Icons to use for buttons, matching an icon defined by the jQuery UI CSS Framework.
- up (string, default: "ui-icon-triangle-1-n")
- down (string, default: "ui-icon-triangle-1-s")
incrementalType: Boolean or Function()
Default:
true
Controls the number of steps taken when holding down a spin button.
Multiple types supported:-
Boolean: When set to
true
, the stepping delta will increase when spun incessantly. When set tofalse
, all steps are equal (as defined by thestep
option). - 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
Default:
null
The maximum allowed value. The element's
Multiple types supported: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
max
option can be passed as a string which will be parsed based on thenumberFormat
andculture
options; otherwise it will fall back to the nativeparseFloat()
method.
minType: Number or String
Default:
null
The minimum allowed value. The element's
Multiple types supported: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
min
option can be passed as a string which will be parsed based on thenumberFormat
andculture
options; otherwise it will fall back to the nativeparseFloat()
method.
numberFormatType: String
Default:
null
pageType: Number
Default:
null
stepType: Number or String
Default:
null
The size of the step to take when spinning via buttons or via the
Multiple types supported: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
step
option can be passed as a string which will be parsed based on thenumberFormat
andculture
options, otherwise it will fall back to the nativeparseFloat
.
Methods
destroy()
Removes the spinner functionality completely. This will return the element back to its pre-init state.
disable()
Disables the spinner.
enable()
Enables the spinner.
option( optionName ) Returns: Object
Gets the value currently associated with the specified
optionName
.-
optionNameType: StringThe name of the option to get.
option() Returns: PlainObject
Gets an object containing key/value pairs representing the current spinner options hash.
option( optionName, value )
Sets the value of the spinner option associated with the specified
optionName
.option( options )
Sets one or more options for the spinner.
-
optionsType: ObjectA map of option-value pairs to set.
stepDown( [steps ] )
Decrements the value by the specified number of steps. Without the parameter, a single step is decremented.
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 ] )
Increments the value by the specified number of steps. Without the parameter, a single step is incremented.
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
Gets the current value as a number. The value is parsed based on the
numberFormat
and culture
options.value( value )
-
valueThe value to set. If passed as a string, the value is parsed based on the
numberFormat
andculture
options.
widget() Returns: jQuery
Returns a
jQuery
object containing the generated wrapper.
Events
change( event, ui )
Triggered when the value of the spinner has changed and the input is no longer focused.
spin( event, ui )
Triggered during increment/decrement (to determine direction of spin compare current value with
ui.value
).
Can be canceled, preventing the value from being updated.
start( event, ui )
Triggered before a spin. Can be canceled, preventing the spin from occurring.
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 > |