Class: TextInputWidget

.ui.TextInputWidget(configopt)

new TextInputWidget(configopt)

TextInputWidgets, like HTML text inputs, can be configured with options that customize the size of the field as well as its presentation. In addition, these widgets can be configured with icons, indicators, an optional validation-pattern (used to determine if an input value is valid or not) and an input filter, which modifies incoming values rather than validating them. Please see the [OOUI documentation on MediaWiki] [1] for more information and examples. This widget can be used inside an HTML form, such as a OO.ui.FormLayout.
Parameters:
Name Type Attributes Description
config Object <optional>
Configuration options
Properties
Name Type Attributes Default Description
type string <optional>
'text' The value of the HTML `type` attribute: 'text', 'password' 'email', 'url' or 'number'.
placeholder string <optional>
Placeholder text
autofocus boolean <optional>
false Use an HTML `autofocus` attribute to instruct the browser to focus this widget.
readOnly boolean <optional>
false Prevent changes to the value of the text input.
maxLength number <optional>
Maximum number of characters allowed in the input.
labelPosition string <optional>
'after' The position of the inline label relative to that of the value or placeholder text: `'before'` or `'after'`
required boolean <optional>
false Mark the field as required with `true`. Implies `indicator: 'required'`. Note that `false` & setting `indicator: 'required' will result in no indicator shown.
autocomplete boolean <optional>
true Should the browser support autocomplete for this field
spellcheck boolean <optional>
Should the browser support spellcheck for this field (`undefined` means leaving it up to the browser).
validate RegExp | function | string <optional>
Validation pattern: when string, a 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); when RegExp, a regular expression that must match the value for it to be considered valid; when Function, a function receiving the value as parameter that must return true, or promise resolving to true, for it to be considered valid.
Mixes In:
Source:
Example
// Example of a text input widget
    var textInput = new OO.ui.TextInputWidget( {
        value: 'Text input'
    } )
    $( 'body' ).append( textInput.$element );

[1]: https://www.mediawiki.org/wiki/OOUI/Widgets/Inputs

Extends

Methods

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
Source:

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
Overrides:
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
Source:
Returns:
Input length
Type
number

getRange() → {Object}

Get an object describing the current selection range in a directional manner
Source:
Returns:
Object containing 'from' and 'to' offsets
Type
Object

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

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

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.
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
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.
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.
Source:
Returns:
Type
boolean

isRequired() → {boolean}

Check if the input is required.
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.
Source:

moveCursorToStart()

Focus the input and move the cursor to the start.
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
Overrides:
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.
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
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
Inherited From:
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'
Source:

setReadOnly(state)

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

setRequired(state)

Set the required state of the input.
Parameters:
Name Type Description
state boolean Make input required
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.
Source:

setValidityFlag(isValidopt)

Sets the 'invalid' flag appropriately.
Parameters:
Name Type Attributes Description
isValid boolean <optional>
Optionally override validation result
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.
Source:

updateThemeClasses()

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