Class: NumberInputWidget

.ui.NumberInputWidget(configopt)

new NumberInputWidget(configopt)

NumberInputWidgets combine a text input (where a value can be entered manually) and two button widgets (to adjust the value in increments) to allow the user to enter a number.
Parameters:
Name Type Attributes Description
config Object <optional>
Configuration options
Properties
Name Type Attributes Default Description
minusButton Object <optional>
Configuration options to pass to the decrementing button widget.
plusButton Object <optional>
Configuration options to pass to the incrementing button widget.
allowInteger boolean <optional>
false Whether the field accepts only integer values.
min number <optional>
-Infinity Minimum allowed value
max number <optional>
Infinity Maximum allowed value
step number <optional>
1 Delta when using the buttons or up/down arrow keys
pageStep number | null <optional>
Delta when using the page-up/page-down keys. Defaults to 10 times #step.
showButtons boolean <optional>
true Whether to show the plus and minus buttons.
Source:
Example
// Example: A NumberInputWidget.
    var numberInput = new OO.ui.NumberInputWidget( {
        label: 'NumberInputWidget',
        input: { value: 5 },
        min: 1,
        max: 10
    } );
    $( 'body' ).append( numberInput.$element );

Extends

Methods

adjustValue(delta)

Adjust the value of the widget
Parameters:
Name Type Description
delta number Adjustment amount
Source:

encapsulateContent(pre, post)

Insert new content either side of a selection.
Parameters:
Name Type Description
pre string Content to be inserted before the selection
post string Content to be inserted after the selection
Inherited From:
Source:

getAllowInteger() → {boolean}

Get whether only integers are allowed
Source:
Returns:
Flag value
Type
boolean

getClosestScrollableElementContainer() → {HTMLElement}

Get closest scrollable container.
Inherited From:
Source:
Returns:
Closest scrollable container
Type
HTMLElement

getData() → {Mixed}

Get element data.
Inherited From:
Source:
Returns:
Element data
Type
Mixed

getElementDocument() → {HTMLDocument}

Get the DOM document.
Inherited From:
Source:
Returns:
Document object
Type
HTMLDocument

getElementGroup() → {OO.ui.mixin.GroupElement|null}

Get group element is in.
Inherited From:
Source:
Returns:
Group element, null if none
Type
OO.ui.mixin.GroupElement | null

getElementId() → {string}

Ensure that the element has an 'id' attribute, setting it to an unique value if it's missing, and return its value.
Inherited From:
Source:
Returns:
Type
string

getElementWindow() → {Window}

Get the DOM window.
Inherited From:
Source:
Returns:
Window object
Type
Window

(protected) getInputElement(config) → {jQuery}

Get input element. Subclasses of OO.ui.InputWidget use the `config` parameter to produce different elements in different circumstances. The element must have a `value` property (like form elements).
Parameters:
Name Type Description
config Object Configuration options
Inherited From:
Source:
Returns:
Input element
Type
jQuery

getInputId() → {string|null}

Get an ID of a labelable node which is part of this widget, if any, to be used for `
Inherited From:
Source:
Returns:
The ID of the labelable element
Type
string | null

getInputLength() → {number}

Get the length of the text input value. This could differ from the length of #getValue if the value gets filtered
Inherited From:
Source:
Returns:
Input length
Type
number

getNumericValue() → {number}

Get the current value of the widget as a number
Source:
Returns:
May be NaN, or an invalid number
Type
number

getRange() → {Array.<number>}

Get the current range
Overrides:
Source:
Returns:
Minimum and maximum values
Type
Array.<number>

(protected) getSaneType(config) → {string|null}

Get sanitized value for 'type' for given config.
Parameters:
Name Type Description
config Object Configuration options
Inherited From:
Source:
Returns:
Type
string | null

getStep() → {Array.<number>}

Get the current stepping values
Source:
Returns:
Step and page step
Type
Array.<number>

getTagName() → {string}

Get the HTML tag name. Override this method to base the result on instance information.
Inherited From:
Source:
Returns:
HTML tag name
Type
string

getValidity() → {jQuery.Promise}

Get the validity of current value. This method returns a promise that resolves if the value is valid and rejects if it isn't. Uses the validation pattern to check for validity.
Inherited From:
Source:
Returns:
A promise that resolves if the value is valid, rejects if not.
Type
jQuery.Promise

getValue() → {string}

Get the value of the input.
Inherited From:
Source:
Returns:
Input value
Type
string

insertContent(content)

Insert new content into the input.
Parameters:
Name Type Description
content string Content to be inserted
Inherited From:
Source:

installParentChangeDetector()

Support function for making #onElementAttach work across browsers. This whole function could be replaced with one line of code using the DOMNodeInsertedIntoDocument event, but it's not supported by Firefox and allegedly deprecated, so we only use it as fallback. Due to MutationObserver performance woes, #onElementAttach is only somewhat reliably called the first time that the element gets attached to the documented.
Inherited From:
Source:

isDisabled() → {boolean}

Check if the widget is disabled.
Inherited From:
Source:
Returns:
Widget is disabled
Type
boolean

isElementAttached() → {boolean}

Check if the element is attached to the DOM
Inherited From:
Source:
Returns:
The element is attached to the DOM
Type
boolean

isReadOnly() → {boolean}

Check if the input is read-only.
Inherited From:
Source:
Returns:
Type
boolean

isRequired() → {boolean}

Check if the input is required.
Inherited From:
Source:
Returns:
Type
boolean

isVisible() → {boolean}

Check if element is visible.
Inherited From:
Source:
Returns:
element is visible
Type
boolean

moveCursorToEnd()

Focus the input and move the cursor to the end.
Inherited From:
Source:

moveCursorToStart()

Focus the input and move the cursor to the start.
Inherited From:
Source:

(protected) restorePreInfuseState(state)

Restore the pre-infusion dynamic state for this widget. This method is called after #$element has been inserted into DOM. The parameter is the return value of #gatherPreInfuseState.
Parameters:
Name Type Description
state Object
Inherited From:
Source:

scrollElementIntoView(configopt) → {jQuery.Promise}

Scroll element into view.
Parameters:
Name Type Attributes Description
config Object <optional>
Configuration options
Inherited From:
Source:
Returns:
Promise which resolves when the scroll is complete
Type
jQuery.Promise

select()

Focus the input and select the entire text.
Inherited From:
Source:

selectRange(from, toopt)

Focus the input and select a specified range within the text.
Parameters:
Name Type Attributes Description
from number Select from offset
to number <optional>
Select to offset, defaults to from
Inherited From:
Source:

setAllowInteger(flag)

Set whether only integers are allowed
Parameters:
Name Type Description
flag boolean
Source:

setData(data)

Set element data.
Parameters:
Name Type Description
data Mixed Element data
Inherited From:
Source:

setDir(dir)

Set the directionality of the input.
Parameters:
Name Type Description
dir string Text directionality: 'ltr', 'rtl' or 'auto'
Inherited From:
Source:

setDisabled(disabled)

Set the 'disabled' state of the widget. When a widget is disabled, it cannot be used and its appearance is updated to reflect this state.
Parameters:
Name Type Description
disabled boolean Disable widget
Overrides:
Source:

setElementGroup(group)

Set group element is in.
Parameters:
Name Type Description
group OO.ui.mixin.GroupElement | null Group element, null if none
Inherited From:
Source:

setElementId(id)

Set the element has an 'id' attribute.
Parameters:
Name Type Description
id string
Inherited From:
Source:

setInputId(id)

Set the 'id' attribute of the `` element.
Parameters:
Name Type Description
id string
Inherited From:
Source:

setLabelPosition(labelPosition)

Set the position of the inline label relative to that of the value: `‘before’` or `‘after’`.
Parameters:
Name Type Description
labelPosition string Label position, 'before' or 'after'
Inherited From:
Source:

setRange(min, max)

Set the range of allowed values
Parameters:
Name Type Description
min number Minimum allowed value
max number Maximum allowed value
Source:

setReadOnly(state)

Set the read-only state of the input.
Parameters:
Name Type Description
state boolean Make input read-only
Inherited From:
Source:

setRequired(state)

Set the required state of the input.
Parameters:
Name Type Description
state boolean Make input required
Inherited From:
Source:

setStep(step, pageStep)

Set the stepping deltas
Parameters:
Name Type Description
step number Normal step
pageStep number | null Page step. If null, 10 * step will be used.
Source:

setValidation(validate)

Set the validation pattern. The validation pattern is either a regular expression, a function, or the symbolic name of a pattern defined by the class: 'non-empty' (the value cannot be an empty string) or 'integer' (the value must contain only numbers).
Parameters:
Name Type Description
validate RegExp | function | string | null Regular expression, function, or the symbolic name of a pattern (either ‘integer’ or ‘non-empty’) defined by the class.
Inherited From:
Source:

setValidityFlag(isValidopt)

Sets the 'invalid' flag appropriately.
Parameters:
Name Type Attributes Description
isValid boolean <optional>
Optionally override validation result
Inherited From:
Source:

setValue(value)

Set the value of the input.
Parameters:
Name Type Description
value string New value
Inherited From:
Source:
Fires:

simulateLabelClick()

Simulate the behavior of clicking on a label (a HTML `
Inherited From:
Source:

supports(methods) → {boolean}

Check if element supports one or more methods.
Parameters:
Name Type Description
methods string | Array.<string> Method or list of methods to check
Inherited From:
Source:
Returns:
All methods are supported
Type
boolean

toggle(showopt)

Toggle visibility of an element.
Parameters:
Name Type Attributes Description
show boolean <optional>
Make element visible, omit to toggle visibility
Inherited From:
Source:
Fires:
  • event:visible

updateDisabled()

Update the disabled state, in case of changes in parent widget.
Inherited From:
Source:

updatePosition()

Update the position of the inline label. This method is called by #setLabelPosition, and can also be called on its own if something causes the label to be mispositioned.
Inherited From:
Source:

updateThemeClasses()

Update the theme-provided classes.
Inherited From:
Source: