Instantiate a combo button widget offering multiple action choices.
Name | Type | Default | Description |
---|---|---|---|
value |
string | Array.<string> | null |
optional
The initial input value(s). |
choices |
Object.<string, *> |
Object containing the selectable choices of the widget. The object keys serve as values for the different choices while the values are used as choice labels. |
|
options |
LuCI.ui.ComboButton.InitOptions |
optional
Object describing the widget specific options to initialize the button. |
Extends
Methods
-
Add new choices to the dropdown menu.
This function adds further choices to an existing dropdown menu, ignoring choice values which are already present.
Name Type Description values
Array.<string> The choice values to add to the dropdown widget.
labels
Object.<string, *> The choice label values to use when adding dropdown choices. If no label is found for a particular choice value, the value itself is used as label text. Choice labels may be any valid value accepted by
LuCI.dom#content
. -
Remove all existing choices from the dropdown menu.
This function removes all preexisting dropdown choices from the widget, keeping only choices currently being selected unless
reset_values
is given, in which case all choices and deselected and removed.Name Type Default Description reset_value
boolean false optional If set to
true
, deselect and remove selected choices as well instead of keeping them. -
Close all open dropdown widgets in the current document.
-
Returns the current validation error
Returns:
Type Description string The validation error at this time -
Check whether the input value was altered by the user.
Returns:
Type Description boolean Returns true
if the input value has been altered by the user orfalse
if it is unchanged. Note that if the user modifies the initial value and changes it back to the original state, it is still reported as changed. -
Check whether the current input value is valid.
Returns:
Type Description boolean Returns true
if the current input value is valid orfalse
if it does not meet the validation constraints. -
Dispatch a custom (synthetic) event in response to received events.
Sets up event handlers on the given target DOM node for the given event names that dispatch a custom event of the given type to the widget root DOM node.
The primary purpose of this function is to set up a series of custom uniform standard events such as
widget-update
,validation-success
,validation-failure
etc. which are triggered by various different widget specific native DOM events.Name Type Description targetNode
Node Specifies the DOM node on which the native event listeners should be registered.
synevent
string The name of the custom event to dispatch to the widget root DOM node.
events
Array.<string> The native DOM events for which event handlers should be registered.
-
Set up listeners for native DOM events that may change the widget value.
Sets up event handlers on the given target DOM node for the given event names which may cause the input value to change completely, such as
change
events in a select menu. In contrast to update events, such change events will not trigger input value validation but they may cause field dependencies to get re-evaluated and will mark the input widget as dirty.Name Type Description targetNode
Node Specifies the DOM node on which the event listeners should be registered.
events
string repeatable The DOM events for which event handlers should be registered.
-
Set the current placeholder value of the input widget.
Name Type Description value
string | Array.<string> | null The placeholder to set for the input element. Only applicable to text inputs, not to radio buttons, selects or similar.
-
Set up listeners for native DOM events that may update the widget value.
Sets up event handlers on the given target DOM node for the given event names which may cause the input value to update, such as
keyup
oronclick
events. In contrast to change events, such update events will trigger input value validation.Name Type Description targetNode
Node Specifies the DOM node on which the event listeners should be registered.
events
string repeatable The DOM events for which event handlers should be registered.
-
Force validation of the current input value.
Usually input validation is automatically triggered by various DOM events bound to the input widget. In some cases it is required though to manually trigger validation runs, e.g. when programmatically altering values.
Type Definitions
-
LuCI.ui.ComboButton.InitOptions
-
ComboButtons support the same properties as
Dropdown.InitOptions
but enforce specific values for some properties and add additional button specific properties.Properties:
Name Type Argument Default Description multiple
boolean false Since ComboButtons never allow selecting multiple actions, this property is forcibly set to
false
.create
boolean false Since ComboButtons never allow creating custom choices, this property is forcibly set to
false
.optional
boolean false Since ComboButtons must always select one action, this property is forcibly set to
false
.classes
Object.<string, string> <optional>
Specifies a mapping of choice values to CSS class names. If an action choice is selected by the user and if a corresponding entry exists in the
classes
object, the class names corresponding to the selected value are set on the button element.This is useful to apply different button styles, such as colors, to the combined button depending on the selected action.
click
function <optional>
Specifies a handler function to invoke when the user clicks the button. This function will be called with the button DOM node as
this
context and receive the DOM click event as first as well as the selected action choice value as second argument.