Expand all

OO.ui.MenuTagMultiselectWidget

Extends

Constructor

MenuTagMultiselectWidget is a OO.ui.TagMultiselectWidget intended to use a menu of selectable options.

Example

// A basic MenuTagMultiselectWidget.
    const widget = new OO.ui.MenuTagMultiselectWidget( {
        inputPosition: 'outline',
        options: [
           { data: 'option1', label: 'Option 1', icon: 'tag' },
           { data: 'option2', label: 'Option 2' },
           { data: 'option3', label: 'Option 3' },
        ],
        selected: [ 'option1', 'option2' ]
    } );
    $( document.body ).append( widget.$element );

Parameters:

Name Type Attributes Description
config Object optional

Configuration object

Properties:
Name Type Attributes Default Description
clearInputOnChoose boolean optional
true

Clear the text input value when a menu option is chosen

menu Object optional

Configuration object for the menu widget

$overlay jQuery optional

An overlay for the menu. See https://www.mediawiki.org/wiki/OOUI/Concepts#Overlays.

options Array.<Object> optional
[]

Array of menu options in the format { data: …, label: … }

Source:

MenuTagMultiselectWidget is a OO.ui.TagMultiselectWidget intended to use a menu of selectable options.

Properties

flags #

Initial value to pass to setFlags if no value is provided in config.

Properties:

Type Description
string | Array.<string> | Object.<string, boolean>
Inherited from:
Mixes in:
Source:
Initial value to pass to setFlags if no value is provided in config.

icon #

The symbolic name of the icon (e.g., ‘remove’ or ‘menu’), or a map of symbolic names. A map is used for i18n purposes and contains a default icon name and additional names keyed by language code. The default name is used when no icon is keyed by the user's language.

Example of an i18n map:

{ default: 'bold-a', en: 'bold-b', de: 'bold-f' }

Note: the static property will be overridden if the #icon configuration is used.

Properties:

Type Description
Object | string
Inherited from:
Mixes in:
Source:
The symbolic name of the icon (e.g., ‘remove’ or ‘menu’), or a map of symbolic names.

iconTitle #

The icon title, displayed when users move the mouse over the icon. The value can be text, a function that returns title text, or null for no title.

The static property will be overridden if the #iconTitle configuration is used.

Properties:

Type Description
string | function | null
Inherited from:
Mixes in:
Source:
The icon title, displayed when users move the mouse over the icon.

indicator #

Symbolic name of the indicator (e.g. ‘required’ or ‘down’). The static property will be overridden if the #indicator configuration is used.

Properties:

Type Description
string | null
Inherited from:
Mixes in:
Source:
Symbolic name of the indicator (e.g.

indicatorTitle #

A text string used as the indicator title, a function that returns title text, or null for no title. The static property will be overridden if the #indicatorTitle configuration is used.

Properties:

Type Description
string | function | null
Inherited from:
Mixes in:
Source:

A text string used as the indicator title, a function that returns title text, or null for no title.

title #

The title text, a function that returns text, or null for no title. The value of the static property is overridden if the #title config option is used.

If the element has a default title (e.g. <input type=file>), null will allow that title to be shown. Use empty string to suppress it.

Properties:

Type Description
string | function | null
Inherited from:
Mixes in:
Source:
The title text, a function that returns text, or null for no title.

Methods

addAllowedValue(value) #

Add a value to the allowed values list

Parameters:

Name Type Description
value any

Allowed data value

Inherited from:
Source:
Add a value to the allowed values list

addOptions(menuOptions) #

Add options to the menu, ensuring that they are unique by data.

Parameters:

Name Type Description
menuOptions Array.<Object>

Object defining options

Source:
Add options to the menu, ensuring that they are unique by data.

addTag(data, [label]) → {boolean} #

Add tag to the display area.

Performs a validation check on the tag to be added.

Parameters:

Name Type Attributes Default Description
data any

Tag data

label string | jQuery optional
data

Tag label. If no label is provided, the stringified version of the data will be used instead.

Inherited from:
Source:

Returns:

Item was added successfully

Type
boolean
Add tag to the display area.

addTagFromInput() #

Add tag from input value

Inherited from:
Source:
Add tag from input value

checkValidity() → {boolean} #

Check whether all items in the widget are valid

Inherited from:
Source:

Returns:

Widget is valid

Type
boolean
Check whether all items in the widget are valid

clearInput() #

Clear the input

createMenuOptionWidget(data, [label], [icon]) → {OO.ui.OptionWidget} #

Create a menu option widget.

Parameters:

Name Type Attributes Default Description
data string

Item data

label string optional
data

Item label

icon string optional

Symbolic icon name

Source:

Returns:

Option widget

Type
OO.ui.OptionWidget
Create a menu option widget.

createMenuWidget(menuConfig) → {OO.ui.MenuSelectWidget} #

Create the menu for this widget. This is in a separate method so that child classes can override this without polluting the constructor with unnecessary extra objects that will be overidden.

Parameters:

Name Type Description
menuConfig Object

Configuration options

Source:

Returns:

Menu widget

Type
OO.ui.MenuSelectWidget
Create the menu for this widget.

createTagItemWidget(data, [label]) → {OO.ui.TagItemWidget}protected #

Construct a OO.ui.TagItemWidget (or a subclass thereof) from given label and data.

Parameters:

Name Type Attributes Default Description
data any

Item data

label string | jQuery optional
data

The label text or JQuery collection.

Inherited from:
Source:

Returns:

Type
OO.ui.TagItemWidget
Construct a OO.ui.TagItemWidget (or a subclass thereof) from given label and data.

doInputArrow(e, direction, [withMetaKey]) #

Perform an action after the Left/Right arrow key on the input, select the previous item from the input. See #getPreviousItem

Parameters:

Name Type Attributes Description
e jQuery.Event

Event data

direction string

Direction of the movement; forwards or backwards

withMetaKey boolean optional

Whether this key was pressed with a meta key like Control

Inherited from:
Source:

Perform an action after the Left/Right arrow key on the input, select the previous item from the input.

doInputBackspace(e, [withMetaKey]) → {boolean} #

Perform an action responding to the Backspace key on the input

Parameters:

Name Type Attributes Description
e jQuery.Event

Event data

withMetaKey boolean optional

Whether this key was pressed with a meta key like Control

Inherited from:
Source:

Returns:

Whether to prevent defaults

Type
boolean
Perform an action responding to the Backspace key on the input

doInputEnter(e, [withMetaKey]) → {boolean} #

Perform an action after the Enter key on the input

Parameters:

Name Type Attributes Description
e jQuery.Event

Event data

withMetaKey boolean optional

Whether this key was pressed with a meta key like Control

Inherited from:
Source:

Returns:

Whether to prevent defaults

Type
boolean
Perform an action after the Enter key on the input

doInputEscape(e) #

Perform an action after the Escape key on the input

Parameters:

Name Type Description
e jQuery.Event

Event data

Inherited from:
Source:
Perform an action after the Escape key on the input

getAllowedValues() → {Array.<string>} #

Get the allowed values list

Overrides:
Source:

Returns:

Allowed data values

Type
Array.<string>
Get the allowed values list

getClosestScrollableElementContainer() → {HTMLElement} #

Get closest scrollable container.

Inherited from:
Source:

Returns:

Closest scrollable container

Type
HTMLElement
Get closest scrollable container.

getData() → {any} #

Get element data.

Inherited from:
Source:

Returns:

Element data

Type
any
Get element data.

getElementDocument() → {HTMLDocument} #

Get the DOM document.

Inherited from:
Source:

Returns:

Document object

Type
HTMLDocument
Get the DOM document.

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
Get group element is in.

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

Ensure that the element has an 'id' attribute, setting it to an unique value if it's missing, and return its value.

getElementWindow() → {Window} #

Get the DOM window.

Inherited from:
Source:

Returns:

Window object

Type
Window
Get the DOM window.

getInputId() → {string|null} #

Get an ID of a labelable node which is part of this widget, if any, to be used for <label for> value.

If this function returns null, the widget should have a meaningful #simulateLabelClick method instead.

Inherited from:
Source:

Returns:

The ID of the labelable element

Type
string | null

Get an ID of a labelable node which is part of this widget, if any, to be used for <label for> value.

getMenu() → {OO.ui.MenuSelectWidget} #

Get the menu

Source:

Returns:

Menu

Type
OO.ui.MenuSelectWidget
Get the menu

getNextItem([item]) → {OO.ui.Widget}protected #

Given an item, returns the item after it. If the item is already the last item, return this.input. If no item is passed, returns the very first item.

Parameters:

Name Type Attributes Description
item OO.ui.TagItemWidget optional

Tag item

Inherited from:
Source:

Returns:

The next widget available.

Type
OO.ui.Widget
Given an item, returns the item after it.

getPreviousItem([item]) → {OO.ui.Widget}protected #

Given an item, returns the item before it. If the item is already the first item, return this.input. If no item is passed, returns the very last item.

Parameters:

Name Type Attributes Description
item OO.ui.TagItemWidget optional

Tag item

Inherited from:
Source:

Returns:

The previous widget available.

Type
OO.ui.Widget
Given an item, returns the item before it.

getTagInfoFromInput() → {Object} #

Get data and label for a new tag from the input value

Overrides:
Source:

Returns:

The data and label for a tag

Type
Object
Get data and label for a new tag from the input value

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
Get the HTML tag name.

getValue() → {Array.<any>} #

Get the datas of the currently selected items

Inherited from:
Source:

Returns:

Datas of currently selected items

Type
Array.<any>
Get the datas of the currently selected items

isAllowedData(data) → {boolean} #

Check whether a given value is allowed to be added

Parameters:

Name Type Description
data any

Requested value

Inherited from:
Source:

Returns:

Value is allowed

Type
boolean
Check whether a given value is allowed to be added

isDisabled() → {boolean} #

Check if the widget is disabled.

Inherited from:
Source:

Returns:

Widget is disabled

Type
boolean
Check if the widget is disabled.

isDuplicateData(data) → {boolean} #

Check whether the given value is a duplicate of an existing tag already in the list.

Parameters:

Name Type Description
data any

Requested value

Inherited from:
Source:

Returns:

Value is duplicate

Type
boolean

Check whether the given value is a duplicate of an existing tag already in the list.

isElementAttached() → {boolean} #

Check if the element is attached to the DOM

Inherited from:
Source:

Returns:

The element is attached to the DOM

Type
boolean
Check if the element is attached to the DOM

isUnderLimit() → {boolean} #

Check whether the number of current tags is within the limit.

Inherited from:
Source:

Returns:

True if current tag count is within the limit or if 'tagLimit' is not set

Type
boolean
Check whether the number of current tags is within the limit.

isValid() → {boolean} #

Get the current valid state of the widget

Inherited from:
Source:

Returns:

Widget is valid

Type
boolean
Get the current valid state of the widget

isVisible() → {boolean} #

Check if element is visible.

Inherited from:
Source:

Returns:

element is visible

Type
boolean
Check if element is visible.

onChangeTags() #

Respond to change event, where items were added, removed, or cleared.

Inherited from:
Source:
Respond to change event, where items were added, removed, or cleared.

onInputBlur() #

Respond to input blur event

Inherited from:
Source:
Respond to input blur event

onInputChange() #

Respond to input change event

Source:
Respond to input change event

onInputFocus() #

Respond to input focus event

Overrides:
Source:
Respond to input focus event

onMenuChoose(menuItem, selected) #

Respond to menu choose event, which is intentional by the user.

Parameters:

Name Type Description
menuItem OO.ui.OptionWidget

Selected menu items

selected boolean

Item is selected

Source:
Respond to menu choose event, which is intentional by the user.

onMenuToggle(isVisible) #

Respond to menu toggle event. Reset item highlights on hide.

Parameters:

Name Type Description
isVisible boolean

The menu is visible

Source:
Respond to menu toggle event.

onResize() #

Respond to resize event

Source:
Respond to resize event

onTagFixed(item) #

Respond to item fixed state change

Parameters:

Name Type Description
item OO.ui.TagItemWidget

Selected item

Inherited from:
Source:
Respond to item fixed state change

onTagNavigate(item, direction) #

Respond to navigate event on the tag

Parameters:

Name Type Description
item OO.ui.TagItemWidget

Removed tag

direction string

Direction of movement; 'forwards' or 'backwards'

Inherited from:
Source:
Respond to navigate event on the tag

onTagRemove(item) #

Respond to tag remove event

Parameters:

Name Type Description
item OO.ui.TagItemWidget

Removed tag

Inherited from:
Source:
Respond to tag remove event

onTagSelect(item) #

Respond to item select event

Parameters:

Name Type Description
item OO.ui.TagItemWidget

Selected item

Overrides:
Source:
Respond to item select event

removeTagByData(data) #

Remove tag by its data property.

Parameters:

Name Type Description
data string | Object

Tag data

Inherited from:
Source:
Remove tag by its data property.

restorePreInfuseState(state)protected #

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:
Restore the pre-infusion dynamic state for this widget.

scrollElementIntoView([config]) → {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
Scroll element into view.

setData(data) → {OO.ui.Element}chainable #

Set element data.

Parameters:

Name Type Description
data any

Element data

Inherited from:
Source:

Returns:

The element, for chaining

Type
OO.ui.Element
Set element data.

setDisabled([disabled]) → {OO.ui.Widget}chainable #

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 Attributes Default Description
disabled boolean optional
false

Disable widget

Overrides:
Source:

Returns:

The widget, for chaining

Type
OO.ui.Widget
Set the 'disabled' state of the widget.

setElementGroup(group) → {OO.ui.Element}chainable #

Set group element is in.

Parameters:

Name Type Description
group OO.ui.mixin.GroupElement | null

Group element, null if none

Inherited from:
Source:

Returns:

The element, for chaining

Type
OO.ui.Element
Set group element is in.

setElementId(id) → {OO.ui.Element}chainable #

Set the element has an 'id' attribute.

Parameters:

Name Type Description
id string
Inherited from:
Source:

Returns:

The element, for chaining

Type
OO.ui.Element
Set the element has an 'id' attribute.

setLabelledBy(id) #

Set the element with the given ID as a label for this widget.

Parameters:

Name Type Description
id string | null
Inherited from:
Source:
Set the element with the given ID as a label for this widget.

setValue(valueObject) #

Set the value of this widget by datas.

Parameters:

Name Type Description
valueObject string | Array.<string> | Object | Array.<Object>

An object representing the data and label of the value. If the widget allows arbitrary values, the items will be added as-is. Otherwise, the data value will be checked against allowedValues. This object must contain at least a data key. Example: { data: 'foo', label: 'Foo item' } For multiple items, use an array of objects. For example: [ { data: 'foo', label: 'Foo item' }, { data: 'bar', label: 'Bar item' } ] Value can also be added with plaintext array, for example: [ 'foo', 'bar', 'bla' ] or a single string, like 'foo'

Overrides:
Source:
Set the value of this widget by datas.

simulateLabelClick() #

Simulate the behavior of clicking on a label (a HTML <label> element) bound to this input. HTML only allows <label> to act on specific "labelable" elements; complex widgets might need to override this method to provide intuitive, accessible behavior.

By default, this does nothing. OO.ui.mixin.TabIndexedElement overrides it for focusable widgets. Individual widgets may override it too.

This method is called by OO.ui.LabelWidget and OO.ui.FieldLayout. It should not be called directly.

Inherited from:
Source:
Simulate the behavior of clicking on a label (a HTML <label> element) bound to this input.

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
Check if element supports one or more methods.

toggle([show]) → {OO.ui.Element}chainable #

Toggle visibility of an element.

Parameters:

Name Type Attributes Description
show boolean optional

Make element visible, omit to toggle visibility

Inherited from:
Source:

Returns:

The element, for chaining

Type
OO.ui.Element

Fires:

Toggle visibility of an element.

toggleValid([valid]) #

Set the valid state of this item

Parameters:

Name Type Attributes Description
valid boolean optional

Item is valid, omit to toggle

Inherited from:
Source:

Fires:

Set the valid state of this item

updateDisabled() → {OO.ui.Widget}chainable #

Update the disabled state, in case of changes in parent widget.

Inherited from:
Source:

Returns:

The widget, for chaining

Type
OO.ui.Widget
Update the disabled state, in case of changes in parent widget.

updateThemeClasses() #

Update the theme-provided classes.

This is called in element mixins and widget classes any time state changes. Updating is debounced, minimizing overhead of changing multiple attributes and guaranteeing that theme updates do not occur within an element's constructor

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

Events

disable(disabled) #

A 'disable' event is emitted when the disabled state of the widget changes (i.e. on disable and enable).

Parameters:

Name Type Description
disabled boolean

Widget is disabled

Inherited from:
Source:

A 'disable' event is emitted when the disabled state of the widget changes (i.e.

toggle(visible) #

A 'toggle' event is emitted when the visibility of the widget changes.

Parameters:

Name Type Description
visible boolean

Widget is visible

Inherited from:
Source:
A 'toggle' event is emitted when the visibility of the widget changes.

valid(valid) #

Parameters:

Name Type Description
valid boolean
Inherited from:
Source: