diff --git a/jsapi/LuCI.form.AbstractValue.html b/jsapi/LuCI.form.AbstractValue.html index 973a3070de..a8c18d1a09 100644 --- a/jsapi/LuCI.form.AbstractValue.html +++ b/jsapi/LuCI.form.AbstractValue.html @@ -1,3 +1,3 @@ Class: AbstractValue
On this page

LuCI.form. AbstractValue

The AbstractValue class serves as an abstract base for the different form option styles implemented by LuCI.form. It provides the common logic for handling option input values, for dependencies among options and for validation constraints that should be applied to entered values.

This class is private and not directly accessible by user code.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

(abstract) render() → {Node|Promise.<Node>}

Render the form element.

The render() function recursively walks the form element tree and renders the markup for each element, returning the assembled DOM tree.

Returns:

May return a DOM Node or a promise resolving to a DOM node containing the form element's markup, including the markup of any child elements.

Type: 
Node | Promise.<Node>

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

(abstract) validate(section_id, value) → {*}

Apply custom validation logic.

This method is invoked whenever incremental validation is performed on the user input, e.g. on keyup or blur events.

The default implementation of this method does nothing and always returns true. User code may override this method to provide additional validation logic which is not covered by data type constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

value*

The value to validate

Returns:

The method shall return true to accept the given value. Any other return value is treated as a failure, converted to a string and displayed as an error message to the user.

Type: 
*

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. AbstractValue

The AbstractValue class serves as an abstract base for the different form option styles implemented by LuCI.form. It provides the common logic for handling option input values, for dependencies among options and for validation constraints that should be applied to entered values.

This class is private and not directly accessible by user code.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

(abstract) render() → {Node|Promise.<Node>}

Render the form element.

The render() function recursively walks the form element tree and renders the markup for each element, returning the assembled DOM tree.

Returns:

May return a DOM Node or a promise resolving to a DOM node containing the form element's markup, including the markup of any child elements.

Type: 
Node | Promise.<Node>

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

(abstract) validate(section_id, value) → {*}

Apply custom validation logic.

This method is invoked whenever incremental validation is performed on the user input, e.g. on keyup or blur events.

The default implementation of this method does nothing and always returns true. User code may override this method to provide additional validation logic which is not covered by data type constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

value*

The value to validate

Returns:

The method shall return true to accept the given value. Any other return value is treated as a failure, converted to a string and displayed as an error message to the user.

Type: 
*

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.Button.html b/jsapi/LuCI.form.Button.html index 4290e061c1..99aa6d23c7 100644 --- a/jsapi/LuCI.form.Button.html +++ b/jsapi/LuCI.form.Button.html @@ -1,3 +1,3 @@ Class: Button
On this page

LuCI.form. Button

The Button element wraps a LuCI.ui.Hiddenfield widget and renders the underlying UCI option or default value as readonly text.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

inputstyle :string

Override the button style class.

By setting this property, a specific cbi-button-* CSS class can be selected to influence the style of the resulting button.

Suitable values which are implemented by most themes are positive, negative and primary.

The default of null means a neutral button styling is used.

Type:
  • string
Default Value
  • null

inputtitle :string|function

Override the rendered button caption.

By default, the option title - which is passed as the fourth argument to the constructor - is used as a caption for the button element. When setting this property to a string, it is used as a String.format() pattern with the underlying UCI section name passed as the first format argument. When set to a function, it is invoked passing the section ID as the sole argument, and the resulting return value is converted to a string before being used as a button caption.

The default of null means the option title is used as caption.

Type:
  • string | function
Default Value
  • null

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

onclick :function

Override the button click action.

By default, the underlying UCI option (or default property) value is copied into a hidden field tied to the button element and the save action is triggered on the parent form element.

When this property is set to a function, it is invoked instead of performing the default actions. The handler function will receive the DOM click element as the first and the underlying configuration section ID as the second argument.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. Button

The Button element wraps a LuCI.ui.Hiddenfield widget and renders the underlying UCI option or default value as readonly text.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

inputstyle :string

Override the button style class.

By setting this property, a specific cbi-button-* CSS class can be selected to influence the style of the resulting button.

Suitable values which are implemented by most themes are positive, negative and primary.

The default of null means a neutral button styling is used.

Type:
  • string
Default Value
  • null

inputtitle :string|function

Override the rendered button caption.

By default, the option title - which is passed as the fourth argument to the constructor - is used as a caption for the button element. When setting this property to a string, it is used as a String.format() pattern with the underlying UCI section name passed as the first format argument. When set to a function, it is invoked passing the section ID as the sole argument, and the resulting return value is converted to a string before being used as a button caption.

The default of null means the option title is used as caption.

Type:
  • string | function
Default Value
  • null

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

onclick :function

Override the button click action.

By default, the underlying UCI option (or default property) value is copied into a hidden field tied to the button element and the save action is triggered on the parent form element.

When this property is set to a function, it is invoked instead of performing the default actions. The handler function will receive the DOM click element as the first and the underlying configuration section ID as the second argument.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.DirectoryPicker.html b/jsapi/LuCI.form.DirectoryPicker.html index 2ee32f7015..63006d0454 100644 --- a/jsapi/LuCI.form.DirectoryPicker.html +++ b/jsapi/LuCI.form.DirectoryPicker.html @@ -1,3 +1,3 @@ Class: DirectoryPicker
On this page

LuCI.form. DirectoryPicker

The DirectoryPicker element wraps a LuCI.ui.FileUpload widget and offers the ability to browse, create, delete and select remote directories.

Extends

Members

browser :boolean

Render the widget in browser mode initially instead of a button to 'Select Directory...'.

Type:
  • boolean
Default Value
  • false

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

directory_create :boolean

Toggle remote directory create functionality.

When set to true, the underlying widget provides a button which lets the user create directories. Note that this is merely a cosmetic feature: remote create permissions are controlled by the session ACL rules.

The default of false means the directory create button is hidden.

Type:
  • boolean
Default Value
  • false

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

enable_download :boolean

Toggle download file functionality.

Type:
  • boolean
Default Value
  • false

enable_remove :boolean

Toggle remote file delete functionality.

When set to true, the underlying widget provides buttons which let the user delete files from remote directories. Note that this is merely a cosmetic feature: remote delete permissions are controlled by the session ACL rules.

The default is false, means file removal buttons are not displayed.

Type:
  • boolean
Default Value
  • false

enable_upload :boolean

Toggle file upload functionality.

When set to true, the underlying widget provides a button which lets the user select and upload local files to the remote system. Note that this is merely a cosmetic feature: remote upload access is controlled by the session ACL rules.

The default of false means file upload functionality is disabled.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

root_directory :string

Specify the root directory for file browsing.

This property defines the topmost directory the file browser widget may navigate to. The UI will not allow browsing directories outside this prefix. Note that this is merely a cosmetic feature: remote file access and directory listing permissions are controlled by the session ACL rules.

The default is /tmp.

Type:
  • string
Default Value
  • /tmp

show_hidden :boolean

Toggle display of hidden files.

Display hidden files when rendering the remote directory listing. Note that this is merely a cosmetic feature: hidden files are always included in received remote file listings.

The default of true means hidden files are displayed.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. DirectoryPicker

The DirectoryPicker element wraps a LuCI.ui.FileUpload widget and offers the ability to browse, create, delete and select remote directories.

Extends

Members

browser :boolean

Render the widget in browser mode initially instead of a button to 'Select Directory...'.

Type:
  • boolean
Default Value
  • false

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

directory_create :boolean

Toggle remote directory create functionality.

When set to true, the underlying widget provides a button which lets the user create directories. Note that this is merely a cosmetic feature: remote create permissions are controlled by the session ACL rules.

The default of false means the directory create button is hidden.

Type:
  • boolean
Default Value
  • false

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

enable_download :boolean

Toggle download file functionality.

Type:
  • boolean
Default Value
  • false

enable_remove :boolean

Toggle remote file delete functionality.

When set to true, the underlying widget provides buttons which let the user delete files from remote directories. Note that this is merely a cosmetic feature: remote delete permissions are controlled by the session ACL rules.

The default is false, means file removal buttons are not displayed.

Type:
  • boolean
Default Value
  • false

enable_upload :boolean

Toggle file upload functionality.

When set to true, the underlying widget provides a button which lets the user select and upload local files to the remote system. Note that this is merely a cosmetic feature: remote upload access is controlled by the session ACL rules.

The default of false means file upload functionality is disabled.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

root_directory :string

Specify the root directory for file browsing.

This property defines the topmost directory the file browser widget may navigate to. The UI will not allow browsing directories outside this prefix. Note that this is merely a cosmetic feature: remote file access and directory listing permissions are controlled by the session ACL rules.

The default is /tmp.

Type:
  • string
Default Value
  • /tmp

show_hidden :boolean

Toggle display of hidden files.

Display hidden files when rendering the remote directory listing. Note that this is merely a cosmetic feature: hidden files are always included in received remote file listings.

The default of true means hidden files are displayed.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.DummyValue.html b/jsapi/LuCI.form.DummyValue.html index bbbbd97b57..e90f0b1118 100644 --- a/jsapi/LuCI.form.DummyValue.html +++ b/jsapi/LuCI.form.DummyValue.html @@ -1,3 +1,3 @@ Class: DummyValue
On this page

LuCI.form. DummyValue

The DummyValue element wraps a LuCI.ui.Hiddenfield widget and renders the underlying UCI option or default value as readonly text.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

hidden :boolean

Render the UCI option value as hidden using the HTML 'display: none' style property.

By default, the value is displayed.

Type:
  • boolean
Default Value
  • null

href :string

Set a URL which is opened when clicking on the dummy value text.

By setting this property, the dummy value text is wrapped in an <a> element with the property value used as href attribute.

Type:
  • string
Default Value
  • null

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

rawhtml :boolean

Treat the UCI option value (or the default property value) as HTML.

By default, the value text is HTML escaped before being rendered as text. In some cases, HTML content may need to be interpreted and rendered as-is. When set to true, HTML escaping is disabled.

Type:
  • boolean
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. DummyValue

The DummyValue element wraps a LuCI.ui.Hiddenfield widget and renders the underlying UCI option or default value as readonly text.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

hidden :boolean

Render the UCI option value as hidden using the HTML 'display: none' style property.

By default, the value is displayed.

Type:
  • boolean
Default Value
  • null

href :string

Set a URL which is opened when clicking on the dummy value text.

By setting this property, the dummy value text is wrapped in an <a> element with the property value used as href attribute.

Type:
  • string
Default Value
  • null

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

rawhtml :boolean

Treat the UCI option value (or the default property value) as HTML.

By default, the value text is HTML escaped before being rendered as text. In some cases, HTML content may need to be interpreted and rendered as-is. When set to true, HTML escaping is disabled.

Type:
  • boolean
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.DynamicList.html b/jsapi/LuCI.form.DynamicList.html index 56bf0461ff..30eccdbd60 100644 --- a/jsapi/LuCI.form.DynamicList.html +++ b/jsapi/LuCI.form.DynamicList.html @@ -1,3 +1,3 @@ Class: DynamicList
On this page

LuCI.form. DynamicList

The DynamicList class represents a multi-value widget allowing the user to enter multiple unique values, optionally selected from a set of predefined choices. It builds upon the LuCI.ui.DynamicList widget.

Extends

Members

allowduplicates :boolean

Allows the underlying form controls to have multiple identical values.

Default is null. If true, the underlying form value will not be checked for duplication.

Type:
  • boolean
Default Value
  • null

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. DynamicList

The DynamicList class represents a multi-value widget allowing the user to enter multiple unique values, optionally selected from a set of predefined choices. It builds upon the LuCI.ui.DynamicList widget.

Extends

Members

allowduplicates :boolean

Allows the underlying form controls to have multiple identical values.

Default is null. If true, the underlying form value will not be checked for duplication.

Type:
  • boolean
Default Value
  • null

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.FileUpload.html b/jsapi/LuCI.form.FileUpload.html index 774f4f2d7f..ad07200bd0 100644 --- a/jsapi/LuCI.form.FileUpload.html +++ b/jsapi/LuCI.form.FileUpload.html @@ -1,3 +1,3 @@ Class: FileUpload
On this page

LuCI.form. FileUpload

The FileUpload element wraps a LuCI.ui.FileUpload widget and offers the ability to browse, upload and select remote files.

Extends

Members

browser :boolean

Render the widget in browser mode initially instead of a button to 'Select File...'.

Type:
  • boolean
Default Value
  • false

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

directory_create :boolean

Toggle remote directory create functionality.

When set to true, the underlying widget provides a button which lets the user create directories. Note that this is merely a cosmetic feature: remote create permissions are controlled by the session ACL rules.

The default of false means the directory create button is hidden.

Type:
  • boolean
Default Value
  • false

directory_select :boolean

Toggle remote directory select functionality.

When set to true, the underlying widget changes behaviour to select directories instead of files, in effect, becoming a directory picker.

The default is false.

Type:
  • boolean
Default Value
  • false

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

enable_download :boolean

Toggle download file functionality.

Type:
  • boolean
Default Value
  • false

enable_remove :boolean

Toggle remote file delete functionality.

When set to true, the underlying widget provides buttons which let the user delete files from remote directories. Note that this is merely a cosmetic feature: remote delete permissions are controlled by the session ACL rules.

The default is true, means file removal buttons are displayed.

Type:
  • boolean
Default Value
  • true

enable_upload :boolean

Toggle file upload functionality.

When set to true, the underlying widget provides a button which lets the user select and upload local files to the remote system. Note that this is merely a cosmetic feature: remote upload access is controlled by the session ACL rules.

The default of true means file upload functionality is displayed.

Type:
  • boolean
Default Value
  • true

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

root_directory :string

Specify the root directory for file browsing.

This property defines the topmost directory the file browser widget may navigate to. The UI will not allow browsing directories outside this prefix. Note that this is merely a cosmetic feature: remote file access and directory listing permissions are controlled by the session ACL rules.

The default is /etc/luci-uploads.

Type:
  • string
Default Value
  • /etc/luci-uploads

show_hidden :boolean

Toggle display of hidden files.

Display hidden files when rendering the remote directory listing. Note that this is merely a cosmetic feature: hidden files are always included in received remote file listings.

The default of false means hidden files are not displayed.

Type:
  • boolean
Default Value
  • false

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. FileUpload

The FileUpload element wraps a LuCI.ui.FileUpload widget and offers the ability to browse, upload and select remote files.

Extends

Members

browser :boolean

Render the widget in browser mode initially instead of a button to 'Select File...'.

Type:
  • boolean
Default Value
  • false

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

directory_create :boolean

Toggle remote directory create functionality.

When set to true, the underlying widget provides a button which lets the user create directories. Note that this is merely a cosmetic feature: remote create permissions are controlled by the session ACL rules.

The default of false means the directory create button is hidden.

Type:
  • boolean
Default Value
  • false

directory_select :boolean

Toggle remote directory select functionality.

When set to true, the underlying widget changes behaviour to select directories instead of files, in effect, becoming a directory picker.

The default is false.

Type:
  • boolean
Default Value
  • false

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

enable_download :boolean

Toggle download file functionality.

Type:
  • boolean
Default Value
  • false

enable_remove :boolean

Toggle remote file delete functionality.

When set to true, the underlying widget provides buttons which let the user delete files from remote directories. Note that this is merely a cosmetic feature: remote delete permissions are controlled by the session ACL rules.

The default is true, means file removal buttons are displayed.

Type:
  • boolean
Default Value
  • true

enable_upload :boolean

Toggle file upload functionality.

When set to true, the underlying widget provides a button which lets the user select and upload local files to the remote system. Note that this is merely a cosmetic feature: remote upload access is controlled by the session ACL rules.

The default of true means file upload functionality is displayed.

Type:
  • boolean
Default Value
  • true

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

root_directory :string

Specify the root directory for file browsing.

This property defines the topmost directory the file browser widget may navigate to. The UI will not allow browsing directories outside this prefix. Note that this is merely a cosmetic feature: remote file access and directory listing permissions are controlled by the session ACL rules.

The default is /etc/luci-uploads.

Type:
  • string
Default Value
  • /etc/luci-uploads

show_hidden :boolean

Toggle display of hidden files.

Display hidden files when rendering the remote directory listing. Note that this is merely a cosmetic feature: hidden files are always included in received remote file listings.

The default of false means hidden files are not displayed.

Type:
  • boolean
Default Value
  • false

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.Flag.html b/jsapi/LuCI.form.Flag.html index fdd03dd102..84c8456ca7 100644 --- a/jsapi/LuCI.form.Flag.html +++ b/jsapi/LuCI.form.Flag.html @@ -1,3 +1,3 @@ Class: Flag
On this page

LuCI.form. Flag

The Flag element builds upon the LuCI.ui.Checkbox widget to implement a simple checkbox element.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

disabled :string

Sets the input value to use for the checkbox unchecked state.

Type:
  • string
Default Value
  • 0

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

enabled :string

Sets the input value to use for the checkbox checked state.

Type:
  • string
Default Value
  • 1

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

tooltip :string|function

Set a tooltip for the flag option.

Set to a string, it will be used as-is as a tooltip.

Set to a function, the function will be invoked and the return value will be shown as a tooltip. If the return value of the function is null no tooltip will be set.

Type:
  • string | function
Default Value
  • null

tooltipicon :string

Set a tooltip icon for the flag option.

If set, this icon will be shown for the default one. This could also be a png icon from the resources directory.

Type:
  • string
Default Value
  • 'ℹ️';

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the checked state of the underlying checkbox widget and return either the enabled or the disabled property value, depending on the checked state.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Query the checked state of the underlying checkbox widget and return either a localized Yes or No string, depending on the checked state.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. Flag

The Flag element builds upon the LuCI.ui.Checkbox widget to implement a simple checkbox element.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

disabled :string

Sets the input value to use for the checkbox unchecked state.

Type:
  • string
Default Value
  • 0

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

enabled :string

Sets the input value to use for the checkbox checked state.

Type:
  • string
Default Value
  • 1

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

tooltip :string|function

Set a tooltip for the flag option.

Set to a string, it will be used as-is as a tooltip.

Set to a function, the function will be invoked and the return value will be shown as a tooltip. If the return value of the function is null no tooltip will be set.

Type:
  • string | function
Default Value
  • null

tooltipicon :string

Set a tooltip icon for the flag option.

If set, this icon will be shown for the default one. This could also be a png icon from the resources directory.

Type:
  • string
Default Value
  • 'ℹ️';

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the checked state of the underlying checkbox widget and return either the enabled or the disabled property value, depending on the checked state.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Query the checked state of the underlying checkbox widget and return either a localized Yes or No string, depending on the checked state.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.GridSection.html b/jsapi/LuCI.form.GridSection.html index 247cbb0ed8..c8449b52c4 100644 --- a/jsapi/LuCI.form.GridSection.html +++ b/jsapi/LuCI.form.GridSection.html @@ -1,3 +1,3 @@ Class: GridSection
On this page

LuCI.form. GridSection

The GridSection class maps all or - if filter() is overridden - a subset of the underlying UCI configuration sections of a given type.

A grid section functions similar to a LuCI.form.TableSection but supports tabbing in the modal overlay. Option elements added with option() are shown in the table while elements added with taboption() are displayed in the modal popup.

Another important difference is that the table cells show a readonly text preview of the corresponding option elements by default, unless the child option element is explicitly made writeable by setting the editable property to true.

Additionally, the grid section honours a modalonly property of child option elements. Refer to the AbstractValue documentation for details.

Layout wise, a grid section looks mostly identical to table sections.

Extends

Members

actionstitle :string|function

Set a custom text for the actions column header row when actions buttons are present.

Type:
  • string | function
Default Value
  • null

addbtntitle :string|function

Override the caption used for the section add button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Add.

Type:
  • string | function
Default Value
  • null

addremove :boolean

If set to true, the user may add or remove instances from the form section widget, otherwise only pre-existing sections may be edited. The default is false.

Type:
  • boolean
Default Value
  • false

anonymous :boolean

If set to true, mapped section instances are treated as anonymous UCI sections, which means that section instance elements will be rendered without a title element and that no name is required when adding new sections. The default is false.

Type:
  • boolean
Default Value
  • false

cloneable :boolean

Set to true, a clone button is added to the button column, allowing the user to clone section instances mapped by the section form element. The default is false.

Type:
  • boolean
Default Value
  • false

clonebtntitle :string|function

Override the caption used for the section clone button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Clone.

Type:
  • string | function
Default Value
  • null

delbtntitle :string|function

Override the caption used for the section delete button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Delete.

Type:
  • string | function
Default Value
  • null

extedit :string|function

Enables a per-section instance row Edit button which triggers a certain action when clicked. Set to a string, the string value is used as a String.format() pattern with the name of the underlying UCI section as the first format argument. The result is then interpreted as a URL which LuCI will navigate to when the user clicks the edit button.

If set to a function, this function will be registered as a click event handler on the rendered edit button, receiving the section instance name as the first and the DOM click event as the second argument.

Type:
  • string | function
Default Value
  • null

filterrow :boolean

Optional table filtering for table sections.

Set filterrow to true to display a filter header row in the generated table with per-column text fields to search for string matches in the column. The filter row appears after the titles row.

The filters work cumulatively: text in each field shall match an entry for the row to be displayed. The results are filtered live. Matching is case-sensitive, and partial, i.e. part or all of the result includes the search string.

The filter fields assume the placeholder text Filter suffixed with the column name, to ease correlation of filter fields to their corresponding column entries on narrow displays which might fold the columns over multiple lines.

Type:
  • boolean
Default Value
  • null

Optional footer row for table sections.

Set footer to one of:

  • a function that returns a table row (tr) or node E('...')
  • an array of string cell contents (first entry maps to the name column if present).

This is useful for providing sum totals, extra function buttons or extra space.

The default implementation returns an empty node.

Type:
  • Array.<string> | function
Default Value
  • `E([])`

hidetitle :boolean

If set to true, the title caption of the form section element which is normally rendered before the start of the section content will not be rendered in the UI. The default is false, meaning that the title is rendered.

Type:
  • boolean
Default Value
  • false

max_cols :number

Specify a maximum amount of columns to display. By default, one table column is rendered for each child option of the form section element. When this option is set to a positive number, then no more columns than the given amount are rendered. When the number of child options exceeds the specified amount, a More… button is rendered in the last column, opening a modal dialog presenting all options elements in NamedSection style when clicked.

Type:
  • number
Default Value
  • null

modaltitle :string|function

Override the per-section instance modal popup title caption shown when clicking the More… button in a section specifying max_cols. Set to a string, it will be used as a String.format() pattern with the name of the underlying UCI section as the first argument. Set to a function, the function will be invoked with the section name as the first argument, and its return value is used as a caption after converting it to a string. If this property is not set, the default is the name of the underlying UCI configuration section.

Type:
  • string | function
Default Value
  • null

nodescriptions :boolean

Set to true, the header row with the descriptions of options will not be displayed. By default, the row of descriptions is automatically displayed when at least one option has a description.

Type:
  • boolean
Default Value
  • false

(readonly) parentoption :LuCI.form.AbstractValue

Access the parent option container instance.

In case this section is nested within an option element container, this property will hold a reference to the parent option instance.

If this section is not nested, the property is null.

rowcolors :boolean

Set to true, alternating cbi-rowstyle-1 and cbi-rowstyle-2 CSS classes are added to the table row elements. Not all LuCI themes implement these row style classes. The default is false.

Type:
  • boolean
Default Value
  • false

sectiontitle :string|function

Override the per-section instance title caption shown in the first column of the table unless anonymous is set to true. Set to a string, it will be used as a String.format() pattern with the name of the underlying UCI section as the first argument. Set to a function, the function will be invoked with the section name as the first argument and its return value used as a caption, after converting it to a string. If this property is not set, the default is the name of the underlying UCI configuration section.

Type:
  • string | function
Default Value
  • null

sortable :boolean

Set to true, a sort button is added to the last column, allowing the user to reorder the section instances mapped by the section form element.

Type:
  • boolean
Default Value
  • false

tabbed :boolean

When set to true, instead of rendering section instances one below another, treat each instance as a separate tab pane and render a tab menu at the top of the form section element, allowing the user to switch among instances. The default is false.

Type:
  • boolean
Default Value
  • false

uciconfig :string

Override the UCI configuration name to read the section IDs from. By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified. The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

Methods

(abstract) addModalOptions(modalSection, section_id, ev) → {*|Promise.<*>}

Add further options to the per-section instanced modal popup.

This function may be overridden by user code to perform additional setup steps before displaying the more options modal which is useful to e.g. query additional data or to inject further option elements.

The default implementation of this function does nothing.

Parameters:
NameTypeDescription
modalSectionLuCI.form.NamedSection

The NamedSection instance about to be rendered in the modal popup.

section_idstring

The ID of the underlying UCI section the modal popup belongs to.

evEvent

The DOM event emitted by clicking the More… button.

Returns:

Return values of this function are ignored but if a promise is returned, it is run to completion before the rendering is continued, allowing custom logic to perform asynchronous work before the modal dialog is shown.

Type: 
* | Promise.<*>

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cfgvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query underlying option configuration values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the configuration values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the configuration value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding configuration values or just a single configuration value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

(abstract) filter(section_id) → {boolean}

Filter UCI section IDs to render.

The filter function is invoked for each UCI section ID of a given type and controls whether the given UCI section is rendered or ignored by the form section element.

The default implementation always returns true. User code or classes extending AbstractSection may override this function with custom implementations.

Parameters:
NameTypeDescription
section_idstring

The UCI section ID to test.

Returns:

Returns true when the given UCI section ID should be handled and false when it should be ignored.

Type: 
boolean

formvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query the underlying option widget input values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the widget input values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the widget input value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

getOption(optionopt) → {null|LuCI.form.AbstractValue|Object.<string, LuCI.form.AbstractValue>}

Obtain underlying option objects.

This function is sensitive to the amount of arguments passed to it; if no option name is specified, all options within this section are returned as a dictionary.

If an option name is supplied, this function returns the matching LuCI.form.AbstractValue instance only.

Parameters:
NameTypeAttributesDescription
optionstring<optional>

The name of the option object to obtain

Returns:

Returns either a dictionary of option names and their corresponding option instance objects or just a single object instance value, depending on the amount of passed arguments.

Type: 
null | LuCI.form.AbstractValue | Object.<string, LuCI.form.AbstractValue>

getUIElement(section_id, optionopt) → {null|LuCI.ui.AbstractElement|Object.<string, (null|LuCI.ui.AbstractElement)>}

Obtain underlying option LuCI.ui widget instances.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the LuCI.ui widget instances of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the LuCI.ui widget instance value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | LuCI.ui.AbstractElement | Object.<string, (null|LuCI.ui.AbstractElement)>

load() → {Promise.<void>}

Load the configuration covered by this section.

The load() function recursively walks the section element tree and invokes the load function of each child option element.

Returns:

Returns a promise resolving once the values of all child elements have been loaded. The promise may reject with an error if any of the child elements' load functions rejected with an error.

Type: 
Promise.<void>

option(optionclass, cbiClass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to the section.

Note that taboption() should be used instead if this form section element uses tabs.

Parameters:
NameTypeAttributesDescription
optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

cbiClassobject

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

args*<repeatable>

argument array

Throws:

Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

Type
TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

parse() → {Promise.<void>}

Parse this sections form input.

The parse() function recursively walks the section element tree and triggers input value reading and validation for each encountered child option element.

Options which are hidden due to unsatisfied dependencies are skipped.

Returns:

Returns a promise resolving once the values of all child elements have been parsed. The returned promise is rejected if any parsed values do not meet the validation constraints of their respective elements.

Type: 
Promise.<void>

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

tab(name, title, descriptionopt)

Add an option tab to the section.

The modal option elements of a grid section may be divided into multiple tabs to provide a better overview to the user.

Before options can be moved into a tab pane, the corresponding tab has to be defined first, which is done by calling this function.

Note that tabs are only effective in modal popups. Options added with option() will not be assigned to a specific tab and are rendered in the table view only.

Parameters:
NameTypeAttributesDescription
namestring

The name of the tab to register. It may be freely chosen and just serves as an identifier to differentiate tabs.

titlestring

The human readable caption of the tab.

descriptionstring<optional>

An additional description text for the corresponding tab pane. It is displayed as a text paragraph below the tab but before the tab pane contents. If omitted, no description will be rendered.

Throws:

Throws an exception if a tab with the same name already exists.

Type
Error

taboption(tabName, optionclass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to a tab of the section.

Parameters:
NameTypeAttributesDescription
tabNamestring

The name of the section tab to add the option element to.

optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

args*<repeatable>

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

Throws:
  • Throws a ReferenceError exception when the given tab name does not exist.

    Type
    ReferenceError
  • Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

    Type
    TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. GridSection

The GridSection class maps all or - if filter() is overridden - a subset of the underlying UCI configuration sections of a given type.

A grid section functions similar to a LuCI.form.TableSection but supports tabbing in the modal overlay. Option elements added with option() are shown in the table while elements added with taboption() are displayed in the modal popup.

Another important difference is that the table cells show a readonly text preview of the corresponding option elements by default, unless the child option element is explicitly made writeable by setting the editable property to true.

Additionally, the grid section honours a modalonly property of child option elements. Refer to the AbstractValue documentation for details.

Layout wise, a grid section looks mostly identical to table sections.

Extends

Members

actionstitle :string|function

Set a custom text for the actions column header row when actions buttons are present.

Type:
  • string | function
Default Value
  • null

addbtntitle :string|function

Override the caption used for the section add button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Add.

Type:
  • string | function
Default Value
  • null

addremove :boolean

If set to true, the user may add or remove instances from the form section widget, otherwise only pre-existing sections may be edited. The default is false.

Type:
  • boolean
Default Value
  • false

anonymous :boolean

If set to true, mapped section instances are treated as anonymous UCI sections, which means that section instance elements will be rendered without a title element and that no name is required when adding new sections. The default is false.

Type:
  • boolean
Default Value
  • false

cloneable :boolean

Set to true, a clone button is added to the button column, allowing the user to clone section instances mapped by the section form element. The default is false.

Type:
  • boolean
Default Value
  • false

clonebtntitle :string|function

Override the caption used for the section clone button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Clone.

Type:
  • string | function
Default Value
  • null

delbtntitle :string|function

Override the caption used for the section delete button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Delete.

Type:
  • string | function
Default Value
  • null

extedit :string|function

Enables a per-section instance row Edit button which triggers a certain action when clicked. Set to a string, the string value is used as a String.format() pattern with the name of the underlying UCI section as the first format argument. The result is then interpreted as a URL which LuCI will navigate to when the user clicks the edit button.

If set to a function, this function will be registered as a click event handler on the rendered edit button, receiving the section instance name as the first and the DOM click event as the second argument.

Type:
  • string | function
Default Value
  • null

filterrow :boolean

Optional table filtering for table sections.

Set filterrow to true to display a filter header row in the generated table with per-column text fields to search for string matches in the column. The filter row appears after the titles row.

The filters work cumulatively: text in each field shall match an entry for the row to be displayed. The results are filtered live. Matching is case-sensitive, and partial, i.e. part or all of the result includes the search string.

The filter fields assume the placeholder text Filter suffixed with the column name, to ease correlation of filter fields to their corresponding column entries on narrow displays which might fold the columns over multiple lines.

Type:
  • boolean
Default Value
  • null

Optional footer row for table sections.

Set footer to one of:

  • a function that returns a table row (tr) or node E('...')
  • an array of string cell contents (first entry maps to the name column if present).

This is useful for providing sum totals, extra function buttons or extra space.

The default implementation returns an empty node.

Type:
  • Array.<string> | function
Default Value
  • `E([])`

hidetitle :boolean

If set to true, the title caption of the form section element which is normally rendered before the start of the section content will not be rendered in the UI. The default is false, meaning that the title is rendered.

Type:
  • boolean
Default Value
  • false

max_cols :number

Specify a maximum amount of columns to display. By default, one table column is rendered for each child option of the form section element. When this option is set to a positive number, then no more columns than the given amount are rendered. When the number of child options exceeds the specified amount, a More… button is rendered in the last column, opening a modal dialog presenting all options elements in NamedSection style when clicked.

Type:
  • number
Default Value
  • null

modaltitle :string|function

Override the per-section instance modal popup title caption shown when clicking the More… button in a section specifying max_cols. Set to a string, it will be used as a String.format() pattern with the name of the underlying UCI section as the first argument. Set to a function, the function will be invoked with the section name as the first argument, and its return value is used as a caption after converting it to a string. If this property is not set, the default is the name of the underlying UCI configuration section.

Type:
  • string | function
Default Value
  • null

nodescriptions :boolean

Set to true, the header row with the descriptions of options will not be displayed. By default, the row of descriptions is automatically displayed when at least one option has a description.

Type:
  • boolean
Default Value
  • false

(readonly) parentoption :LuCI.form.AbstractValue

Access the parent option container instance.

In case this section is nested within an option element container, this property will hold a reference to the parent option instance.

If this section is not nested, the property is null.

rowcolors :boolean

Set to true, alternating cbi-rowstyle-1 and cbi-rowstyle-2 CSS classes are added to the table row elements. Not all LuCI themes implement these row style classes. The default is false.

Type:
  • boolean
Default Value
  • false

sectiontitle :string|function

Override the per-section instance title caption shown in the first column of the table unless anonymous is set to true. Set to a string, it will be used as a String.format() pattern with the name of the underlying UCI section as the first argument. Set to a function, the function will be invoked with the section name as the first argument and its return value used as a caption, after converting it to a string. If this property is not set, the default is the name of the underlying UCI configuration section.

Type:
  • string | function
Default Value
  • null

sortable :boolean

Set to true, a sort button is added to the last column, allowing the user to reorder the section instances mapped by the section form element.

Type:
  • boolean
Default Value
  • false

tabbed :boolean

When set to true, instead of rendering section instances one below another, treat each instance as a separate tab pane and render a tab menu at the top of the form section element, allowing the user to switch among instances. The default is false.

Type:
  • boolean
Default Value
  • false

uciconfig :string

Override the UCI configuration name to read the section IDs from. By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified. The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

Methods

(abstract) addModalOptions(modalSection, section_id, ev) → {*|Promise.<*>}

Add further options to the per-section instanced modal popup.

This function may be overridden by user code to perform additional setup steps before displaying the more options modal which is useful to e.g. query additional data or to inject further option elements.

The default implementation of this function does nothing.

Parameters:
NameTypeDescription
modalSectionLuCI.form.NamedSection

The NamedSection instance about to be rendered in the modal popup.

section_idstring

The ID of the underlying UCI section the modal popup belongs to.

evEvent

The DOM event emitted by clicking the More… button.

Returns:

Return values of this function are ignored but if a promise is returned, it is run to completion before the rendering is continued, allowing custom logic to perform asynchronous work before the modal dialog is shown.

Type: 
* | Promise.<*>

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cfgvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query underlying option configuration values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the configuration values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the configuration value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding configuration values or just a single configuration value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

(abstract) filter(section_id) → {boolean}

Filter UCI section IDs to render.

The filter function is invoked for each UCI section ID of a given type and controls whether the given UCI section is rendered or ignored by the form section element.

The default implementation always returns true. User code or classes extending AbstractSection may override this function with custom implementations.

Parameters:
NameTypeDescription
section_idstring

The UCI section ID to test.

Returns:

Returns true when the given UCI section ID should be handled and false when it should be ignored.

Type: 
boolean

formvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query the underlying option widget input values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the widget input values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the widget input value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

getOption(optionopt) → {null|LuCI.form.AbstractValue|Object.<string, LuCI.form.AbstractValue>}

Obtain underlying option objects.

This function is sensitive to the amount of arguments passed to it; if no option name is specified, all options within this section are returned as a dictionary.

If an option name is supplied, this function returns the matching LuCI.form.AbstractValue instance only.

Parameters:
NameTypeAttributesDescription
optionstring<optional>

The name of the option object to obtain

Returns:

Returns either a dictionary of option names and their corresponding option instance objects or just a single object instance value, depending on the amount of passed arguments.

Type: 
null | LuCI.form.AbstractValue | Object.<string, LuCI.form.AbstractValue>

getUIElement(section_id, optionopt) → {null|LuCI.ui.AbstractElement|Object.<string, (null|LuCI.ui.AbstractElement)>}

Obtain underlying option LuCI.ui widget instances.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the LuCI.ui widget instances of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the LuCI.ui widget instance value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | LuCI.ui.AbstractElement | Object.<string, (null|LuCI.ui.AbstractElement)>

load() → {Promise.<void>}

Load the configuration covered by this section.

The load() function recursively walks the section element tree and invokes the load function of each child option element.

Returns:

Returns a promise resolving once the values of all child elements have been loaded. The promise may reject with an error if any of the child elements' load functions rejected with an error.

Type: 
Promise.<void>

option(optionclass, cbiClass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to the section.

Note that taboption() should be used instead if this form section element uses tabs.

Parameters:
NameTypeAttributesDescription
optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

cbiClassobject

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

args*<repeatable>

argument array

Throws:

Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

Type
TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

parse() → {Promise.<void>}

Parse this sections form input.

The parse() function recursively walks the section element tree and triggers input value reading and validation for each encountered child option element.

Options which are hidden due to unsatisfied dependencies are skipped.

Returns:

Returns a promise resolving once the values of all child elements have been parsed. The returned promise is rejected if any parsed values do not meet the validation constraints of their respective elements.

Type: 
Promise.<void>

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

tab(name, title, descriptionopt)

Add an option tab to the section.

The modal option elements of a grid section may be divided into multiple tabs to provide a better overview to the user.

Before options can be moved into a tab pane, the corresponding tab has to be defined first, which is done by calling this function.

Note that tabs are only effective in modal popups. Options added with option() will not be assigned to a specific tab and are rendered in the table view only.

Parameters:
NameTypeAttributesDescription
namestring

The name of the tab to register. It may be freely chosen and just serves as an identifier to differentiate tabs.

titlestring

The human readable caption of the tab.

descriptionstring<optional>

An additional description text for the corresponding tab pane. It is displayed as a text paragraph below the tab but before the tab pane contents. If omitted, no description will be rendered.

Throws:

Throws an exception if a tab with the same name already exists.

Type
Error

taboption(tabName, optionclass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to a tab of the section.

Parameters:
NameTypeAttributesDescription
tabNamestring

The name of the section tab to add the option element to.

optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

args*<repeatable>

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

Throws:
  • Throws a ReferenceError exception when the given tab name does not exist.

    Type
    ReferenceError
  • Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

    Type
    TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.HiddenValue.html b/jsapi/LuCI.form.HiddenValue.html index 09067cfe1b..81cf68fcd0 100644 --- a/jsapi/LuCI.form.HiddenValue.html +++ b/jsapi/LuCI.form.HiddenValue.html @@ -1,3 +1,3 @@ Class: HiddenValue
On this page

LuCI.form. HiddenValue

The HiddenValue element wraps a LuCI.ui.Hiddenfield widget.

Hidden value widgets used to be necessary in legacy code which actually submitted the underlying HTML form the server. With client side handling of forms, there are more efficient ways to store hidden state data.

Since this widget has no visible content, the title and description values of this form element should be set to null as well to avoid a broken or distorted form layout when rendering the option element.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. HiddenValue

The HiddenValue element wraps a LuCI.ui.Hiddenfield widget.

Hidden value widgets used to be necessary in legacy code which actually submitted the underlying HTML form the server. With client side handling of forms, there are more efficient ways to store hidden state data.

Since this widget has no visible content, the title and description values of this form element should be set to null as well to avoid a broken or distorted form layout when rendering the option element.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.ListValue.html b/jsapi/LuCI.form.ListValue.html index 8c203ef914..713d0972af 100644 --- a/jsapi/LuCI.form.ListValue.html +++ b/jsapi/LuCI.form.ListValue.html @@ -1,3 +1,3 @@ Class: ListValue
On this page

LuCI.form. ListValue

The ListValue class implements a simple static HTML select element allowing the user to choose a single value from a set of predefined choices. It builds upon the LuCI.ui.Select widget.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

orientation :string

Set the orientation of the underlying radio or checkbox elements.

May be one of horizontal or vertical. Only applies to non-select widget types.

Type:
  • string
Default Value
  • horizontal

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

size :number

Set the size attribute of the underlying HTML select element.

Type:
  • number
Default Value
  • null

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

widget :string

Set the type of the underlying form controls.

May be one of select or radio. If set to select, an HTML select element is rendered, otherwise a collection of radio elements is used.

Type:
  • string
Default Value
  • select

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. ListValue

The ListValue class implements a simple static HTML select element allowing the user to choose a single value from a set of predefined choices. It builds upon the LuCI.ui.Select widget.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

orientation :string

Set the orientation of the underlying radio or checkbox elements.

May be one of horizontal or vertical. Only applies to non-select widget types.

Type:
  • string
Default Value
  • horizontal

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

size :number

Set the size attribute of the underlying HTML select element.

Type:
  • number
Default Value
  • null

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

widget :string

Set the type of the underlying form controls.

May be one of select or radio. If set to select, an HTML select element is rendered, otherwise a collection of radio elements is used.

Type:
  • string
Default Value
  • select

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.MultiValue.html b/jsapi/LuCI.form.MultiValue.html index fd0c2fd4a6..57a129dc1a 100644 --- a/jsapi/LuCI.form.MultiValue.html +++ b/jsapi/LuCI.form.MultiValue.html @@ -1,3 +1,3 @@ Class: MultiValue
On this page

LuCI.form. MultiValue

The MultiValue class is a modified variant of the DynamicList element which leverages the LuCI.ui.Dropdown widget to implement a multi select dropdown element.

Extends

Members

allowduplicates :boolean

Allows the underlying form controls to have multiple identical values.

Default is null. If true, the underlying form value will not be checked for duplication.

Type:
  • boolean
Default Value
  • null

create :boolean

Allows custom value entry in addition to those already specified.

Type:
  • boolean
Default Value
  • null

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

display_size :number

Allows specifying the display_items property of the underlying dropdown widget. If omitted, the value of the size property is used or 3 when size is also unspecified.

Type:
  • number
Default Value
  • null

Allows specifying the dropdown_items property of the underlying dropdown widget. If omitted, the value of the size property is used or -1 when size is also unspecified.

Type:
  • number
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. MultiValue

The MultiValue class is a modified variant of the DynamicList element which leverages the LuCI.ui.Dropdown widget to implement a multi select dropdown element.

Extends

Members

allowduplicates :boolean

Allows the underlying form controls to have multiple identical values.

Default is null. If true, the underlying form value will not be checked for duplication.

Type:
  • boolean
Default Value
  • null

create :boolean

Allows custom value entry in addition to those already specified.

Type:
  • boolean
Default Value
  • null

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

display_size :number

Allows specifying the display_items property of the underlying dropdown widget. If omitted, the value of the size property is used or 3 when size is also unspecified.

Type:
  • number
Default Value
  • null

Allows specifying the dropdown_items property of the underlying dropdown widget. If omitted, the value of the size property is used or -1 when size is also unspecified.

Type:
  • number
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.NamedSection.html b/jsapi/LuCI.form.NamedSection.html index 0cc6d7dcc5..395ef9e59b 100644 --- a/jsapi/LuCI.form.NamedSection.html +++ b/jsapi/LuCI.form.NamedSection.html @@ -1,3 +1,3 @@ Class: NamedSection
On this page

LuCI.form. NamedSection

The NamedSection class maps exactly one UCI section instance which is specified when constructing the class instance.

Layout and functionality wise, a named section is essentially a TypedSection which allows exactly one section node.

Extends

Members

(readonly) parentoption :LuCI.form.AbstractValue

Access the parent option container instance.

In case this section is nested within an option element container, this property will hold a reference to the parent option instance.

If this section is not nested, the property is null.

(static) addremove :boolean

Set to true, the user may remove or recreate the sole mapped configuration instance from the form section widget, otherwise only a pre-existing section may be edited. The default is false.

Type:
  • boolean
Default Value
  • false

(static) hidetitle :boolean

If set to true, the title caption of the form section element which is normally rendered before the start of the section content will not be rendered in the UI. The default is false, meaning that the title is rendered.

Type:
  • boolean
Default Value
  • false

(static) uciconfig :string

Override the UCI configuration name to read the section IDs from. By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified. The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cfgsections() → {Array.<string>}

The NamedSection class overrides the generic cfgsections() implementation to return a one-element array containing the mapped section ID as a sole element. User code should not normally change this.

Returns:

Returns a one-element array containing the mapped section ID.

Type: 
Array.<string>

cfgvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query underlying option configuration values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the configuration values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the configuration value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding configuration values or just a single configuration value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

(abstract) filter(section_id) → {boolean}

Filter UCI section IDs to render.

The filter function is invoked for each UCI section ID of a given type and controls whether the given UCI section is rendered or ignored by the form section element.

The default implementation always returns true. User code or classes extending AbstractSection may override this function with custom implementations.

Parameters:
NameTypeDescription
section_idstring

The UCI section ID to test.

Returns:

Returns true when the given UCI section ID should be handled and false when it should be ignored.

Type: 
boolean

formvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query the underlying option widget input values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the widget input values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the widget input value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

getOption(optionopt) → {null|LuCI.form.AbstractValue|Object.<string, LuCI.form.AbstractValue>}

Obtain underlying option objects.

This function is sensitive to the amount of arguments passed to it; if no option name is specified, all options within this section are returned as a dictionary.

If an option name is supplied, this function returns the matching LuCI.form.AbstractValue instance only.

Parameters:
NameTypeAttributesDescription
optionstring<optional>

The name of the option object to obtain

Returns:

Returns either a dictionary of option names and their corresponding option instance objects or just a single object instance value, depending on the amount of passed arguments.

Type: 
null | LuCI.form.AbstractValue | Object.<string, LuCI.form.AbstractValue>

getUIElement(section_id, optionopt) → {null|LuCI.ui.AbstractElement|Object.<string, (null|LuCI.ui.AbstractElement)>}

Obtain underlying option LuCI.ui widget instances.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the LuCI.ui widget instances of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the LuCI.ui widget instance value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | LuCI.ui.AbstractElement | Object.<string, (null|LuCI.ui.AbstractElement)>

load() → {Promise.<void>}

Load the configuration covered by this section.

The load() function recursively walks the section element tree and invokes the load function of each child option element.

Returns:

Returns a promise resolving once the values of all child elements have been loaded. The promise may reject with an error if any of the child elements' load functions rejected with an error.

Type: 
Promise.<void>

option(optionclass, cbiClass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to the section.

Note that taboption() should be used instead if this form section element uses tabs.

Parameters:
NameTypeAttributesDescription
optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

cbiClassobject

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

args*<repeatable>

argument array

Throws:

Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

Type
TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

parse() → {Promise.<void>}

Parse this sections form input.

The parse() function recursively walks the section element tree and triggers input value reading and validation for each encountered child option element.

Options which are hidden due to unsatisfied dependencies are skipped.

Returns:

Returns a promise resolving once the values of all child elements have been parsed. The returned promise is rejected if any parsed values do not meet the validation constraints of their respective elements.

Type: 
Promise.<void>

render() → {Node|Promise.<Node>}

Render the form element.

The render() function recursively walks the form element tree and renders the markup for each element, returning the assembled DOM tree.

Returns:

May return a DOM Node or a promise resolving to a DOM node containing the form element's markup, including the markup of any child elements.

Type: 
Node | Promise.<Node>

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

tab(name, title, descriptionopt)

Add an option tab to the section.

The child option elements of a section may be divided into multiple tabs to provide a better overview to the user.

Before options can be moved into a tab pane, the corresponding tab has to be defined first, which is done by calling this function.

Note that once tabs are defined, user code must use the taboption() method to add options to specific tabs. Option elements added by option() will not be assigned to any tab and not be rendered in this case.

Parameters:
NameTypeAttributesDescription
namestring

The name of the tab to register. It may be freely chosen and just serves as an identifier to differentiate tabs.

titlestring

The human readable caption of the tab.

descriptionstring<optional>

An additional description text for the corresponding tab pane. It is displayed as a text paragraph below the tab but before the tab pane contents. If omitted, no description will be rendered.

Throws:

Throws an exception if a tab with the same name already exists.

Type
Error

taboption(tabName, optionclass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to a tab of the section.

Parameters:
NameTypeAttributesDescription
tabNamestring

The name of the section tab to add the option element to.

optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

args*<repeatable>

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

Throws:
  • Throws a ReferenceError exception when the given tab name does not exist.

    Type
    ReferenceError
  • Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

    Type
    TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. NamedSection

The NamedSection class maps exactly one UCI section instance which is specified when constructing the class instance.

Layout and functionality wise, a named section is essentially a TypedSection which allows exactly one section node.

Extends

Members

(readonly) parentoption :LuCI.form.AbstractValue

Access the parent option container instance.

In case this section is nested within an option element container, this property will hold a reference to the parent option instance.

If this section is not nested, the property is null.

(static) addremove :boolean

Set to true, the user may remove or recreate the sole mapped configuration instance from the form section widget, otherwise only a pre-existing section may be edited. The default is false.

Type:
  • boolean
Default Value
  • false

(static) hidetitle :boolean

If set to true, the title caption of the form section element which is normally rendered before the start of the section content will not be rendered in the UI. The default is false, meaning that the title is rendered.

Type:
  • boolean
Default Value
  • false

(static) uciconfig :string

Override the UCI configuration name to read the section IDs from. By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified. The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cfgsections() → {Array.<string>}

The NamedSection class overrides the generic cfgsections() implementation to return a one-element array containing the mapped section ID as a sole element. User code should not normally change this.

Returns:

Returns a one-element array containing the mapped section ID.

Type: 
Array.<string>

cfgvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query underlying option configuration values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the configuration values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the configuration value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding configuration values or just a single configuration value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

(abstract) filter(section_id) → {boolean}

Filter UCI section IDs to render.

The filter function is invoked for each UCI section ID of a given type and controls whether the given UCI section is rendered or ignored by the form section element.

The default implementation always returns true. User code or classes extending AbstractSection may override this function with custom implementations.

Parameters:
NameTypeDescription
section_idstring

The UCI section ID to test.

Returns:

Returns true when the given UCI section ID should be handled and false when it should be ignored.

Type: 
boolean

formvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query the underlying option widget input values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the widget input values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the widget input value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

getOption(optionopt) → {null|LuCI.form.AbstractValue|Object.<string, LuCI.form.AbstractValue>}

Obtain underlying option objects.

This function is sensitive to the amount of arguments passed to it; if no option name is specified, all options within this section are returned as a dictionary.

If an option name is supplied, this function returns the matching LuCI.form.AbstractValue instance only.

Parameters:
NameTypeAttributesDescription
optionstring<optional>

The name of the option object to obtain

Returns:

Returns either a dictionary of option names and their corresponding option instance objects or just a single object instance value, depending on the amount of passed arguments.

Type: 
null | LuCI.form.AbstractValue | Object.<string, LuCI.form.AbstractValue>

getUIElement(section_id, optionopt) → {null|LuCI.ui.AbstractElement|Object.<string, (null|LuCI.ui.AbstractElement)>}

Obtain underlying option LuCI.ui widget instances.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the LuCI.ui widget instances of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the LuCI.ui widget instance value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | LuCI.ui.AbstractElement | Object.<string, (null|LuCI.ui.AbstractElement)>

load() → {Promise.<void>}

Load the configuration covered by this section.

The load() function recursively walks the section element tree and invokes the load function of each child option element.

Returns:

Returns a promise resolving once the values of all child elements have been loaded. The promise may reject with an error if any of the child elements' load functions rejected with an error.

Type: 
Promise.<void>

option(optionclass, cbiClass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to the section.

Note that taboption() should be used instead if this form section element uses tabs.

Parameters:
NameTypeAttributesDescription
optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

cbiClassobject

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

args*<repeatable>

argument array

Throws:

Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

Type
TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

parse() → {Promise.<void>}

Parse this sections form input.

The parse() function recursively walks the section element tree and triggers input value reading and validation for each encountered child option element.

Options which are hidden due to unsatisfied dependencies are skipped.

Returns:

Returns a promise resolving once the values of all child elements have been parsed. The returned promise is rejected if any parsed values do not meet the validation constraints of their respective elements.

Type: 
Promise.<void>

render() → {Node|Promise.<Node>}

Render the form element.

The render() function recursively walks the form element tree and renders the markup for each element, returning the assembled DOM tree.

Returns:

May return a DOM Node or a promise resolving to a DOM node containing the form element's markup, including the markup of any child elements.

Type: 
Node | Promise.<Node>

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

tab(name, title, descriptionopt)

Add an option tab to the section.

The child option elements of a section may be divided into multiple tabs to provide a better overview to the user.

Before options can be moved into a tab pane, the corresponding tab has to be defined first, which is done by calling this function.

Note that once tabs are defined, user code must use the taboption() method to add options to specific tabs. Option elements added by option() will not be assigned to any tab and not be rendered in this case.

Parameters:
NameTypeAttributesDescription
namestring

The name of the tab to register. It may be freely chosen and just serves as an identifier to differentiate tabs.

titlestring

The human readable caption of the tab.

descriptionstring<optional>

An additional description text for the corresponding tab pane. It is displayed as a text paragraph below the tab but before the tab pane contents. If omitted, no description will be rendered.

Throws:

Throws an exception if a tab with the same name already exists.

Type
Error

taboption(tabName, optionclass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to a tab of the section.

Parameters:
NameTypeAttributesDescription
tabNamestring

The name of the section tab to add the option element to.

optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

args*<repeatable>

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

Throws:
  • Throws a ReferenceError exception when the given tab name does not exist.

    Type
    ReferenceError
  • Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

    Type
    TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.RangeSliderValue.html b/jsapi/LuCI.form.RangeSliderValue.html index da59f988ed..8f9b489f23 100644 --- a/jsapi/LuCI.form.RangeSliderValue.html +++ b/jsapi/LuCI.form.RangeSliderValue.html @@ -1,3 +1,3 @@ Class: RangeSliderValue
On this page

LuCI.form. RangeSliderValue

The RangeSliderValue class implements a range slider input using LuCI.ui.RangeSlider. It is useful in cases where a value shall fall within a predetermined range. This helps omit various error checks for such values. The currently chosen value is displayed to the side of the slider.

Extends

Members

calculate :function

Override the calculate action.

When this property is set to a function, it is invoked when the slider is adjusted. This might be useful to calculate and display a result which is more meaningful than the currently chosen value. The calculated value is displayed below the slider.

Type:
  • function
Default Value
  • null

calcunits :string

Define the units of the calculated value.

Suffix a unit string to the calculated value, e.g. 'seconds' or 'dBm'.

Type:
  • string
Default Value
  • null

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :string

Set the default value for the slider. The default value is elided during save: meaning, a currently chosen value which matches the default is not saved.

Type:
  • string
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

max :number

Maximum value the slider can represent.

Type:
  • number
Default Value
  • 100

min :number

Minimum value the slider can represent.

Type:
  • number
Default Value
  • 0

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

step :string

Step size for each tick of the slider, or the special value "any" when handling arbitrary precision floating point numbers.

Type:
  • string
Default Value
  • 1

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns the currently selected value if it does not match the default. If the currently selected value matches the default value, returns null.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. RangeSliderValue

The RangeSliderValue class implements a range slider input using LuCI.ui.RangeSlider. It is useful in cases where a value shall fall within a predetermined range. This helps omit various error checks for such values. The currently chosen value is displayed to the side of the slider.

Extends

Members

calculate :function

Override the calculate action.

When this property is set to a function, it is invoked when the slider is adjusted. This might be useful to calculate and display a result which is more meaningful than the currently chosen value. The calculated value is displayed below the slider.

Type:
  • function
Default Value
  • null

calcunits :string

Define the units of the calculated value.

Suffix a unit string to the calculated value, e.g. 'seconds' or 'dBm'.

Type:
  • string
Default Value
  • null

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :string

Set the default value for the slider. The default value is elided during save: meaning, a currently chosen value which matches the default is not saved.

Type:
  • string
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

max :number

Maximum value the slider can represent.

Type:
  • number
Default Value
  • 100

min :number

Minimum value the slider can represent.

Type:
  • number
Default Value
  • 0

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

step :string

Step size for each tick of the slider, or the special value "any" when handling arbitrary precision floating point numbers.

Type:
  • string
Default Value
  • 1

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns the currently selected value if it does not match the default. If the currently selected value matches the default value, returns null.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

Inherited From

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.RichListValue.html b/jsapi/LuCI.form.RichListValue.html index 98848a72c8..c51f881203 100644 --- a/jsapi/LuCI.form.RichListValue.html +++ b/jsapi/LuCI.form.RichListValue.html @@ -1,3 +1,3 @@ Class: RichListValue
On this page

LuCI.form. RichListValue

The RichListValue class implements a simple static HTML select element allowing the user to choose a single value from a set of predefined choices. Each choice may contain a tertiary, more elaborate description. It builds upon the LuCI.form.ListValue widget.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

orientation :string

Set the orientation of the underlying radio or checkbox elements.

May be one of horizontal or vertical. Only applies to non-select widget types.

Type:
  • string
Default Value
  • horizontal

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

size :number

Set the size attribute of the underlying HTML select element.

Type:
  • number
Default Value
  • null

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

widget :string

Set the type of the underlying form controls.

May be one of select or radio. If set to select, an HTML select element is rendered, otherwise a collection of radio elements is used.

Type:
  • string
Default Value
  • select

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(value, title, description)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
valuestring

The choice value to add.

titleNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as caption.

descriptionNode | string

The description text of the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the value element is implemented as a simple ListValue entry.

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. RichListValue

The RichListValue class implements a simple static HTML select element allowing the user to choose a single value from a set of predefined choices. Each choice may contain a tertiary, more elaborate description. It builds upon the LuCI.form.ListValue widget.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

orientation :string

Set the orientation of the underlying radio or checkbox elements.

May be one of horizontal or vertical. Only applies to non-select widget types.

Type:
  • string
Default Value
  • horizontal

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

size :number

Set the size attribute of the underlying HTML select element.

Type:
  • number
Default Value
  • null

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

widget :string

Set the type of the underlying form controls.

May be one of select or radio. If set to select, an HTML select element is rendered, otherwise a collection of radio elements is used.

Type:
  • string
Default Value
  • select

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(value, title, description)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
valuestring

The choice value to add.

titleNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as caption.

descriptionNode | string

The description text of the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the value element is implemented as a simple ListValue entry.

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.SectionValue.html b/jsapi/LuCI.form.SectionValue.html index df02e809ed..da5d73a8e1 100644 --- a/jsapi/LuCI.form.SectionValue.html +++ b/jsapi/LuCI.form.SectionValue.html @@ -1,3 +1,3 @@ Class: SectionValue
On this page

LuCI.form. SectionValue

The SectionValue widget embeds a form section element within an option element container, allowing to nest form sections into other sections.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

(static, readonly) subsection :LuCI.form.AbstractSection

Access the embedded section instance.

This property holds a reference to the instantiated nested section.

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {null}

Since the section container is not tied to any UCI configuration, its cfgvalue() implementation will always return null.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:
Type: 
null

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {null}

Since the section container is not tied to any UCI configuration, its formvalue() implementation will always return null.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:
Type: 
null

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Since the section container is not tied to any UCI configuration, its remove() implementation is a no-op.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Since the section container is not rendering an own widget, its value() implementation is a no-op.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

write(section_id, formvalue) → {null}

Since the section container is not tied to any UCI configuration, its write() implementation is a no-op.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. SectionValue

The SectionValue widget embeds a form section element within an option element container, allowing to nest form sections into other sections.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

(static, readonly) subsection :LuCI.form.AbstractSection

Access the embedded section instance.

This property holds a reference to the instantiated nested section.

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {null}

Since the section container is not tied to any UCI configuration, its cfgvalue() implementation will always return null.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:
Type: 
null

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {null}

Since the section container is not tied to any UCI configuration, its formvalue() implementation will always return null.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:
Type: 
null

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Since the section container is not tied to any UCI configuration, its remove() implementation is a no-op.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Since the section container is not rendering an own widget, its value() implementation is a no-op.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

write(section_id, formvalue) → {null}

Since the section container is not tied to any UCI configuration, its write() implementation is a no-op.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.TableSection.html b/jsapi/LuCI.form.TableSection.html index 6040ffd4c9..24a03eb910 100644 --- a/jsapi/LuCI.form.TableSection.html +++ b/jsapi/LuCI.form.TableSection.html @@ -1,3 +1,3 @@ Class: TableSection
On this page

LuCI.form. TableSection

The TableSection class maps all or - if filter() is overridden - a subset of the underlying UCI configuration sections of a given type.

Layout wise, the configuration section instances mapped by the section element (sometimes referred to as "section nodes") are rendered as rows within an HTML table element, with an optional section remove button in the last column and a section add button below the table, depending on the value of the addremove property.

Extends

Members

actionstitle :string|function

Set a custom text for the actions column header row when actions buttons are present.

Type:
  • string | function
Default Value
  • null

addbtntitle :string|function

Override the caption used for the section add button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Add.

Type:
  • string | function
Default Value
  • null

addremove :boolean

If set to true, the user may add or remove instances from the form section widget, otherwise only pre-existing sections may be edited. The default is false.

Type:
  • boolean
Default Value
  • false

anonymous :boolean

If set to true, mapped section instances are treated as anonymous UCI sections, which means that section instance elements will be rendered without a title element and that no name is required when adding new sections. The default is false.

Type:
  • boolean
Default Value
  • false

cloneable :boolean

Set to true, a clone button is added to the button column, allowing the user to clone section instances mapped by the section form element. The default is false.

Type:
  • boolean
Default Value
  • false

clonebtntitle :string|function

Override the caption used for the section clone button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Clone.

Type:
  • string | function
Default Value
  • null

delbtntitle :string|function

Override the caption used for the section delete button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Delete.

Type:
  • string | function
Default Value
  • null

extedit :string|function

Enables a per-section instance row Edit button which triggers a certain action when clicked. Set to a string, the string value is used as a String.format() pattern with the name of the underlying UCI section as the first format argument. The result is then interpreted as a URL which LuCI will navigate to when the user clicks the edit button.

If set to a function, this function will be registered as a click event handler on the rendered edit button, receiving the section instance name as the first and the DOM click event as the second argument.

Type:
  • string | function
Default Value
  • null

filterrow :boolean

Optional table filtering for table sections.

Set filterrow to true to display a filter header row in the generated table with per-column text fields to search for string matches in the column. The filter row appears after the titles row.

The filters work cumulatively: text in each field shall match an entry for the row to be displayed. The results are filtered live. Matching is case-sensitive, and partial, i.e. part or all of the result includes the search string.

The filter fields assume the placeholder text Filter suffixed with the column name, to ease correlation of filter fields to their corresponding column entries on narrow displays which might fold the columns over multiple lines.

Type:
  • boolean
Default Value
  • null

Optional footer row for table sections.

Set footer to one of:

  • a function that returns a table row (tr) or node E('...')
  • an array of string cell contents (first entry maps to the name column if present).

This is useful for providing sum totals, extra function buttons or extra space.

The default implementation returns an empty node.

Type:
  • Array.<string> | function
Default Value
  • `E([])`

hidetitle :boolean

If set to true, the title caption of the form section element which is normally rendered before the start of the section content will not be rendered in the UI. The default is false, meaning that the title is rendered.

Type:
  • boolean
Default Value
  • false

max_cols :number

Specify a maximum amount of columns to display. By default, one table column is rendered for each child option of the form section element. When this option is set to a positive number, then no more columns than the given amount are rendered. When the number of child options exceeds the specified amount, a More… button is rendered in the last column, opening a modal dialog presenting all options elements in NamedSection style when clicked.

Type:
  • number
Default Value
  • null

modaltitle :string|function

Override the per-section instance modal popup title caption shown when clicking the More… button in a section specifying max_cols. Set to a string, it will be used as a String.format() pattern with the name of the underlying UCI section as the first argument. Set to a function, the function will be invoked with the section name as the first argument, and its return value is used as a caption after converting it to a string. If this property is not set, the default is the name of the underlying UCI configuration section.

Type:
  • string | function
Default Value
  • null

nodescriptions :boolean

Set to true, the header row with the descriptions of options will not be displayed. By default, the row of descriptions is automatically displayed when at least one option has a description.

Type:
  • boolean
Default Value
  • false

(readonly) parentoption :LuCI.form.AbstractValue

Access the parent option container instance.

In case this section is nested within an option element container, this property will hold a reference to the parent option instance.

If this section is not nested, the property is null.

rowcolors :boolean

Set to true, alternating cbi-rowstyle-1 and cbi-rowstyle-2 CSS classes are added to the table row elements. Not all LuCI themes implement these row style classes. The default is false.

Type:
  • boolean
Default Value
  • false

sectiontitle :string|function

Override the per-section instance title caption shown in the first column of the table unless anonymous is set to true. Set to a string, it will be used as a String.format() pattern with the name of the underlying UCI section as the first argument. Set to a function, the function will be invoked with the section name as the first argument and its return value used as a caption, after converting it to a string. If this property is not set, the default is the name of the underlying UCI configuration section.

Type:
  • string | function
Default Value
  • null

sortable :boolean

Set to true, a sort button is added to the last column, allowing the user to reorder the section instances mapped by the section form element.

Type:
  • boolean
Default Value
  • false

tabbed :boolean

When set to true, instead of rendering section instances one below another, treat each instance as a separate tab pane and render a tab menu at the top of the form section element, allowing the user to switch among instances. The default is false.

Type:
  • boolean
Default Value
  • false

uciconfig :string

Override the UCI configuration name to read the section IDs from. By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified. The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

Methods

(abstract) addModalOptions(modalSection, section_id, ev) → {*|Promise.<*>}

Add further options to the per-section instanced modal popup.

This function may be overridden by user code to perform additional setup steps before displaying the more options modal which is useful to e.g. query additional data or to inject further option elements.

The default implementation of this function does nothing.

Parameters:
NameTypeDescription
modalSectionLuCI.form.NamedSection

The NamedSection instance about to be rendered in the modal popup.

section_idstring

The ID of the underlying UCI section the modal popup belongs to.

evEvent

The DOM event emitted by clicking the More… button.

Returns:

Return values of this function are ignored but if a promise is returned, it is run to completion before the rendering is continued, allowing custom logic to perform asynchronous work before the modal dialog is shown.

Type: 
* | Promise.<*>

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cfgvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query underlying option configuration values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the configuration values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the configuration value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding configuration values or just a single configuration value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

(abstract) filter(section_id) → {boolean}

Filter UCI section IDs to render.

The filter function is invoked for each UCI section ID of a given type and controls whether the given UCI section is rendered or ignored by the form section element.

The default implementation always returns true. User code or classes extending AbstractSection may override this function with custom implementations.

Parameters:
NameTypeDescription
section_idstring

The UCI section ID to test.

Returns:

Returns true when the given UCI section ID should be handled and false when it should be ignored.

Type: 
boolean

formvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query the underlying option widget input values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the widget input values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the widget input value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

getOption(optionopt) → {null|LuCI.form.AbstractValue|Object.<string, LuCI.form.AbstractValue>}

Obtain underlying option objects.

This function is sensitive to the amount of arguments passed to it; if no option name is specified, all options within this section are returned as a dictionary.

If an option name is supplied, this function returns the matching LuCI.form.AbstractValue instance only.

Parameters:
NameTypeAttributesDescription
optionstring<optional>

The name of the option object to obtain

Returns:

Returns either a dictionary of option names and their corresponding option instance objects or just a single object instance value, depending on the amount of passed arguments.

Type: 
null | LuCI.form.AbstractValue | Object.<string, LuCI.form.AbstractValue>

getUIElement(section_id, optionopt) → {null|LuCI.ui.AbstractElement|Object.<string, (null|LuCI.ui.AbstractElement)>}

Obtain underlying option LuCI.ui widget instances.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the LuCI.ui widget instances of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the LuCI.ui widget instance value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | LuCI.ui.AbstractElement | Object.<string, (null|LuCI.ui.AbstractElement)>

load() → {Promise.<void>}

Load the configuration covered by this section.

The load() function recursively walks the section element tree and invokes the load function of each child option element.

Returns:

Returns a promise resolving once the values of all child elements have been loaded. The promise may reject with an error if any of the child elements' load functions rejected with an error.

Type: 
Promise.<void>

option(optionclass, cbiClass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to the section.

Note that taboption() should be used instead if this form section element uses tabs.

Parameters:
NameTypeAttributesDescription
optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

cbiClassobject

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

args*<repeatable>

argument array

Throws:

Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

Type
TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

parse() → {Promise.<void>}

Parse this sections form input.

The parse() function recursively walks the section element tree and triggers input value reading and validation for each encountered child option element.

Options which are hidden due to unsatisfied dependencies are skipped.

Returns:

Returns a promise resolving once the values of all child elements have been parsed. The returned promise is rejected if any parsed values do not meet the validation constraints of their respective elements.

Type: 
Promise.<void>

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

tab(name, title, descriptionopt)

The TableSection implementation does not support option tabbing, so its implementation of tab() will always throw an exception when invoked.

Parameters:
NameTypeAttributesDescription
namestring

The name of the tab to register. It may be freely chosen and just serves as an identifier to differentiate tabs.

titlestring

The human readable caption of the tab.

descriptionstring<optional>

An additional description text for the corresponding tab pane. It is displayed as a text paragraph below the tab but before the tab pane contents. If omitted, no description will be rendered.

Throws:

Throws an exception when invoked.

Type
string

taboption(tabName, optionclass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to a tab of the section.

Parameters:
NameTypeAttributesDescription
tabNamestring

The name of the section tab to add the option element to.

optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

args*<repeatable>

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

Throws:
  • Throws a ReferenceError exception when the given tab name does not exist.

    Type
    ReferenceError
  • Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

    Type
    TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. TableSection

The TableSection class maps all or - if filter() is overridden - a subset of the underlying UCI configuration sections of a given type.

Layout wise, the configuration section instances mapped by the section element (sometimes referred to as "section nodes") are rendered as rows within an HTML table element, with an optional section remove button in the last column and a section add button below the table, depending on the value of the addremove property.

Extends

Members

actionstitle :string|function

Set a custom text for the actions column header row when actions buttons are present.

Type:
  • string | function
Default Value
  • null

addbtntitle :string|function

Override the caption used for the section add button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Add.

Type:
  • string | function
Default Value
  • null

addremove :boolean

If set to true, the user may add or remove instances from the form section widget, otherwise only pre-existing sections may be edited. The default is false.

Type:
  • boolean
Default Value
  • false

anonymous :boolean

If set to true, mapped section instances are treated as anonymous UCI sections, which means that section instance elements will be rendered without a title element and that no name is required when adding new sections. The default is false.

Type:
  • boolean
Default Value
  • false

cloneable :boolean

Set to true, a clone button is added to the button column, allowing the user to clone section instances mapped by the section form element. The default is false.

Type:
  • boolean
Default Value
  • false

clonebtntitle :string|function

Override the caption used for the section clone button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Clone.

Type:
  • string | function
Default Value
  • null

delbtntitle :string|function

Override the caption used for the section delete button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Delete.

Type:
  • string | function
Default Value
  • null

extedit :string|function

Enables a per-section instance row Edit button which triggers a certain action when clicked. Set to a string, the string value is used as a String.format() pattern with the name of the underlying UCI section as the first format argument. The result is then interpreted as a URL which LuCI will navigate to when the user clicks the edit button.

If set to a function, this function will be registered as a click event handler on the rendered edit button, receiving the section instance name as the first and the DOM click event as the second argument.

Type:
  • string | function
Default Value
  • null

filterrow :boolean

Optional table filtering for table sections.

Set filterrow to true to display a filter header row in the generated table with per-column text fields to search for string matches in the column. The filter row appears after the titles row.

The filters work cumulatively: text in each field shall match an entry for the row to be displayed. The results are filtered live. Matching is case-sensitive, and partial, i.e. part or all of the result includes the search string.

The filter fields assume the placeholder text Filter suffixed with the column name, to ease correlation of filter fields to their corresponding column entries on narrow displays which might fold the columns over multiple lines.

Type:
  • boolean
Default Value
  • null

Optional footer row for table sections.

Set footer to one of:

  • a function that returns a table row (tr) or node E('...')
  • an array of string cell contents (first entry maps to the name column if present).

This is useful for providing sum totals, extra function buttons or extra space.

The default implementation returns an empty node.

Type:
  • Array.<string> | function
Default Value
  • `E([])`

hidetitle :boolean

If set to true, the title caption of the form section element which is normally rendered before the start of the section content will not be rendered in the UI. The default is false, meaning that the title is rendered.

Type:
  • boolean
Default Value
  • false

max_cols :number

Specify a maximum amount of columns to display. By default, one table column is rendered for each child option of the form section element. When this option is set to a positive number, then no more columns than the given amount are rendered. When the number of child options exceeds the specified amount, a More… button is rendered in the last column, opening a modal dialog presenting all options elements in NamedSection style when clicked.

Type:
  • number
Default Value
  • null

modaltitle :string|function

Override the per-section instance modal popup title caption shown when clicking the More… button in a section specifying max_cols. Set to a string, it will be used as a String.format() pattern with the name of the underlying UCI section as the first argument. Set to a function, the function will be invoked with the section name as the first argument, and its return value is used as a caption after converting it to a string. If this property is not set, the default is the name of the underlying UCI configuration section.

Type:
  • string | function
Default Value
  • null

nodescriptions :boolean

Set to true, the header row with the descriptions of options will not be displayed. By default, the row of descriptions is automatically displayed when at least one option has a description.

Type:
  • boolean
Default Value
  • false

(readonly) parentoption :LuCI.form.AbstractValue

Access the parent option container instance.

In case this section is nested within an option element container, this property will hold a reference to the parent option instance.

If this section is not nested, the property is null.

rowcolors :boolean

Set to true, alternating cbi-rowstyle-1 and cbi-rowstyle-2 CSS classes are added to the table row elements. Not all LuCI themes implement these row style classes. The default is false.

Type:
  • boolean
Default Value
  • false

sectiontitle :string|function

Override the per-section instance title caption shown in the first column of the table unless anonymous is set to true. Set to a string, it will be used as a String.format() pattern with the name of the underlying UCI section as the first argument. Set to a function, the function will be invoked with the section name as the first argument and its return value used as a caption, after converting it to a string. If this property is not set, the default is the name of the underlying UCI configuration section.

Type:
  • string | function
Default Value
  • null

sortable :boolean

Set to true, a sort button is added to the last column, allowing the user to reorder the section instances mapped by the section form element.

Type:
  • boolean
Default Value
  • false

tabbed :boolean

When set to true, instead of rendering section instances one below another, treat each instance as a separate tab pane and render a tab menu at the top of the form section element, allowing the user to switch among instances. The default is false.

Type:
  • boolean
Default Value
  • false

uciconfig :string

Override the UCI configuration name to read the section IDs from. By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified. The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

Methods

(abstract) addModalOptions(modalSection, section_id, ev) → {*|Promise.<*>}

Add further options to the per-section instanced modal popup.

This function may be overridden by user code to perform additional setup steps before displaying the more options modal which is useful to e.g. query additional data or to inject further option elements.

The default implementation of this function does nothing.

Parameters:
NameTypeDescription
modalSectionLuCI.form.NamedSection

The NamedSection instance about to be rendered in the modal popup.

section_idstring

The ID of the underlying UCI section the modal popup belongs to.

evEvent

The DOM event emitted by clicking the More… button.

Returns:

Return values of this function are ignored but if a promise is returned, it is run to completion before the rendering is continued, allowing custom logic to perform asynchronous work before the modal dialog is shown.

Type: 
* | Promise.<*>

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cfgvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query underlying option configuration values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the configuration values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the configuration value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding configuration values or just a single configuration value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

(abstract) filter(section_id) → {boolean}

Filter UCI section IDs to render.

The filter function is invoked for each UCI section ID of a given type and controls whether the given UCI section is rendered or ignored by the form section element.

The default implementation always returns true. User code or classes extending AbstractSection may override this function with custom implementations.

Parameters:
NameTypeDescription
section_idstring

The UCI section ID to test.

Returns:

Returns true when the given UCI section ID should be handled and false when it should be ignored.

Type: 
boolean

formvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query the underlying option widget input values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the widget input values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the widget input value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

getOption(optionopt) → {null|LuCI.form.AbstractValue|Object.<string, LuCI.form.AbstractValue>}

Obtain underlying option objects.

This function is sensitive to the amount of arguments passed to it; if no option name is specified, all options within this section are returned as a dictionary.

If an option name is supplied, this function returns the matching LuCI.form.AbstractValue instance only.

Parameters:
NameTypeAttributesDescription
optionstring<optional>

The name of the option object to obtain

Returns:

Returns either a dictionary of option names and their corresponding option instance objects or just a single object instance value, depending on the amount of passed arguments.

Type: 
null | LuCI.form.AbstractValue | Object.<string, LuCI.form.AbstractValue>

getUIElement(section_id, optionopt) → {null|LuCI.ui.AbstractElement|Object.<string, (null|LuCI.ui.AbstractElement)>}

Obtain underlying option LuCI.ui widget instances.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the LuCI.ui widget instances of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the LuCI.ui widget instance value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | LuCI.ui.AbstractElement | Object.<string, (null|LuCI.ui.AbstractElement)>

load() → {Promise.<void>}

Load the configuration covered by this section.

The load() function recursively walks the section element tree and invokes the load function of each child option element.

Returns:

Returns a promise resolving once the values of all child elements have been loaded. The promise may reject with an error if any of the child elements' load functions rejected with an error.

Type: 
Promise.<void>

option(optionclass, cbiClass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to the section.

Note that taboption() should be used instead if this form section element uses tabs.

Parameters:
NameTypeAttributesDescription
optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

cbiClassobject

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

args*<repeatable>

argument array

Throws:

Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

Type
TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

parse() → {Promise.<void>}

Parse this sections form input.

The parse() function recursively walks the section element tree and triggers input value reading and validation for each encountered child option element.

Options which are hidden due to unsatisfied dependencies are skipped.

Returns:

Returns a promise resolving once the values of all child elements have been parsed. The returned promise is rejected if any parsed values do not meet the validation constraints of their respective elements.

Type: 
Promise.<void>

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

tab(name, title, descriptionopt)

The TableSection implementation does not support option tabbing, so its implementation of tab() will always throw an exception when invoked.

Parameters:
NameTypeAttributesDescription
namestring

The name of the tab to register. It may be freely chosen and just serves as an identifier to differentiate tabs.

titlestring

The human readable caption of the tab.

descriptionstring<optional>

An additional description text for the corresponding tab pane. It is displayed as a text paragraph below the tab but before the tab pane contents. If omitted, no description will be rendered.

Throws:

Throws an exception when invoked.

Type
string

taboption(tabName, optionclass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to a tab of the section.

Parameters:
NameTypeAttributesDescription
tabNamestring

The name of the section tab to add the option element to.

optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

args*<repeatable>

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

Throws:
  • Throws a ReferenceError exception when the given tab name does not exist.

    Type
    ReferenceError
  • Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

    Type
    TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.TextValue.html b/jsapi/LuCI.form.TextValue.html index 4a0afbbaf8..d3349b6198 100644 --- a/jsapi/LuCI.form.TextValue.html +++ b/jsapi/LuCI.form.TextValue.html @@ -1,3 +1,3 @@ Class: TextValue
On this page

LuCI.form. TextValue

The TextValue class implements a multi-line textarea input using LuCI.ui.Textarea.

Extends

Members

cols :number

Allows specifying the cols property of the underlying textarea widget.

Type:
  • number
Default Value
  • null

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

monospace :boolean

Enforces the use of a monospace font for the textarea contents when set to true.

Type:
  • boolean
Default Value
  • false

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

rows :number

Allows specifying the rows property of the underlying textarea widget.

Type:
  • number
Default Value
  • null

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

wrap :number

Allows specifying the wrap property of the underlying textarea widget.

Type:
  • number
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. TextValue

The TextValue class implements a multi-line textarea input using LuCI.ui.Textarea.

Extends

Members

cols :number

Allows specifying the cols property of the underlying textarea widget.

Type:
  • number
Default Value
  • null

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

monospace :boolean

Enforces the use of a monospace font for the textarea contents when set to true.

Type:
  • boolean
Default Value
  • false

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

rows :number

Allows specifying the rows property of the underlying textarea widget.

Type:
  • number
Default Value
  • null

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

wrap :number

Allows specifying the wrap property of the underlying textarea widget.

Type:
  • number
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.TypedSection.html b/jsapi/LuCI.form.TypedSection.html index d61faaa14e..d784e728f9 100644 --- a/jsapi/LuCI.form.TypedSection.html +++ b/jsapi/LuCI.form.TypedSection.html @@ -1,3 +1,3 @@ Class: TypedSection
On this page

LuCI.form. TypedSection

The TypedSection class maps all or - if filter() is overridden - a subset of the underlying UCI configuration sections of a given type.

Layout wise, the configuration section instances mapped by the section element (sometimes referred to as "section nodes") are stacked beneath each other in a single column, with an optional section remove button next to each section node and a section add button at the end, depending on the value of the addremove property.

Extends

Members

addbtntitle :string|function

Override the caption used for the section add button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Add.

Type:
  • string | function
Default Value
  • null

addremove :boolean

If set to true, the user may add or remove instances from the form section widget, otherwise only pre-existing sections may be edited. The default is false.

Type:
  • boolean
Default Value
  • false

anonymous :boolean

If set to true, mapped section instances are treated as anonymous UCI sections, which means that section instance elements will be rendered without a title element and that no name is required when adding new sections. The default is false.

Type:
  • boolean
Default Value
  • false

delbtntitle :string|function

Override the caption used for the section delete button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Delete.

Type:
  • string | function
Default Value
  • null

hidetitle :boolean

If set to true, the title caption of the form section element which is normally rendered before the start of the section content will not be rendered in the UI. The default is false, meaning that the title is rendered.

Type:
  • boolean
Default Value
  • false

(readonly) parentoption :LuCI.form.AbstractValue

Access the parent option container instance.

In case this section is nested within an option element container, this property will hold a reference to the parent option instance.

If this section is not nested, the property is null.

tabbed :boolean

When set to true, instead of rendering section instances one below another, treat each instance as a separate tab pane and render a tab menu at the top of the form section element, allowing the user to switch among instances. The default is false.

Type:
  • boolean
Default Value
  • false

uciconfig :string

Override the UCI configuration name to read the section IDs from. By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified. The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cfgsections() → {Array.<string>}

Enumerate the UCI section IDs covered by this form section element.

Throws:

Throws an InternalError exception if the function is not implemented.

Type
InternalError
Returns:

Returns an array of UCI section IDs covered by this form element. The sections will be rendered in the same order as the returned array.

Type: 
Array.<string>

cfgvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query underlying option configuration values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the configuration values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the configuration value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding configuration values or just a single configuration value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

(abstract) filter(section_id) → {boolean}

Filter UCI section IDs to render.

The filter function is invoked for each UCI section ID of a given type and controls whether the given UCI section is rendered or ignored by the form section element.

The default implementation always returns true. User code or classes extending AbstractSection may override this function with custom implementations.

Parameters:
NameTypeDescription
section_idstring

The UCI section ID to test.

Returns:

Returns true when the given UCI section ID should be handled and false when it should be ignored.

Type: 
boolean

formvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query the underlying option widget input values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the widget input values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the widget input value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

getOption(optionopt) → {null|LuCI.form.AbstractValue|Object.<string, LuCI.form.AbstractValue>}

Obtain underlying option objects.

This function is sensitive to the amount of arguments passed to it; if no option name is specified, all options within this section are returned as a dictionary.

If an option name is supplied, this function returns the matching LuCI.form.AbstractValue instance only.

Parameters:
NameTypeAttributesDescription
optionstring<optional>

The name of the option object to obtain

Returns:

Returns either a dictionary of option names and their corresponding option instance objects or just a single object instance value, depending on the amount of passed arguments.

Type: 
null | LuCI.form.AbstractValue | Object.<string, LuCI.form.AbstractValue>

getUIElement(section_id, optionopt) → {null|LuCI.ui.AbstractElement|Object.<string, (null|LuCI.ui.AbstractElement)>}

Obtain underlying option LuCI.ui widget instances.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the LuCI.ui widget instances of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the LuCI.ui widget instance value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | LuCI.ui.AbstractElement | Object.<string, (null|LuCI.ui.AbstractElement)>

load() → {Promise.<void>}

Load the configuration covered by this section.

The load() function recursively walks the section element tree and invokes the load function of each child option element.

Returns:

Returns a promise resolving once the values of all child elements have been loaded. The promise may reject with an error if any of the child elements' load functions rejected with an error.

Type: 
Promise.<void>

option(optionclass, cbiClass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to the section.

Note that taboption() should be used instead if this form section element uses tabs.

Parameters:
NameTypeAttributesDescription
optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

cbiClassobject

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

args*<repeatable>

argument array

Throws:

Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

Type
TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

parse() → {Promise.<void>}

Parse this sections form input.

The parse() function recursively walks the section element tree and triggers input value reading and validation for each encountered child option element.

Options which are hidden due to unsatisfied dependencies are skipped.

Returns:

Returns a promise resolving once the values of all child elements have been parsed. The returned promise is rejected if any parsed values do not meet the validation constraints of their respective elements.

Type: 
Promise.<void>

render() → {Node|Promise.<Node>}

Render the form element.

The render() function recursively walks the form element tree and renders the markup for each element, returning the assembled DOM tree.

Returns:

May return a DOM Node or a promise resolving to a DOM node containing the form element's markup, including the markup of any child elements.

Type: 
Node | Promise.<Node>

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

tab(name, title, descriptionopt)

Add an option tab to the section.

The child option elements of a section may be divided into multiple tabs to provide a better overview to the user.

Before options can be moved into a tab pane, the corresponding tab has to be defined first, which is done by calling this function.

Note that once tabs are defined, user code must use the taboption() method to add options to specific tabs. Option elements added by option() will not be assigned to any tab and not be rendered in this case.

Parameters:
NameTypeAttributesDescription
namestring

The name of the tab to register. It may be freely chosen and just serves as an identifier to differentiate tabs.

titlestring

The human readable caption of the tab.

descriptionstring<optional>

An additional description text for the corresponding tab pane. It is displayed as a text paragraph below the tab but before the tab pane contents. If omitted, no description will be rendered.

Throws:

Throws an exception if a tab with the same name already exists.

Type
Error

taboption(tabName, optionclass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to a tab of the section.

Parameters:
NameTypeAttributesDescription
tabNamestring

The name of the section tab to add the option element to.

optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

args*<repeatable>

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

Throws:
  • Throws a ReferenceError exception when the given tab name does not exist.

    Type
    ReferenceError
  • Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

    Type
    TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. TypedSection

The TypedSection class maps all or - if filter() is overridden - a subset of the underlying UCI configuration sections of a given type.

Layout wise, the configuration section instances mapped by the section element (sometimes referred to as "section nodes") are stacked beneath each other in a single column, with an optional section remove button next to each section node and a section add button at the end, depending on the value of the addremove property.

Extends

Members

addbtntitle :string|function

Override the caption used for the section add button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Add.

Type:
  • string | function
Default Value
  • null

addremove :boolean

If set to true, the user may add or remove instances from the form section widget, otherwise only pre-existing sections may be edited. The default is false.

Type:
  • boolean
Default Value
  • false

anonymous :boolean

If set to true, mapped section instances are treated as anonymous UCI sections, which means that section instance elements will be rendered without a title element and that no name is required when adding new sections. The default is false.

Type:
  • boolean
Default Value
  • false

delbtntitle :string|function

Override the caption used for the section delete button at the bottom of the section form element. Set to a string, it will be used as-is. Set to a function, the function will be invoked and its return value is used as a caption, after converting it to a string. If this property is not set, the default is Delete.

Type:
  • string | function
Default Value
  • null

hidetitle :boolean

If set to true, the title caption of the form section element which is normally rendered before the start of the section content will not be rendered in the UI. The default is false, meaning that the title is rendered.

Type:
  • boolean
Default Value
  • false

(readonly) parentoption :LuCI.form.AbstractValue

Access the parent option container instance.

In case this section is nested within an option element container, this property will hold a reference to the parent option instance.

If this section is not nested, the property is null.

tabbed :boolean

When set to true, instead of rendering section instances one below another, treat each instance as a separate tab pane and render a tab menu at the top of the form section element, allowing the user to switch among instances. The default is false.

Type:
  • boolean
Default Value
  • false

uciconfig :string

Override the UCI configuration name to read the section IDs from. By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified. The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cfgsections() → {Array.<string>}

Enumerate the UCI section IDs covered by this form section element.

Throws:

Throws an InternalError exception if the function is not implemented.

Type
InternalError
Returns:

Returns an array of UCI section IDs covered by this form element. The sections will be rendered in the same order as the returned array.

Type: 
Array.<string>

cfgvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query underlying option configuration values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the configuration values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the configuration value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding configuration values or just a single configuration value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

(abstract) filter(section_id) → {boolean}

Filter UCI section IDs to render.

The filter function is invoked for each UCI section ID of a given type and controls whether the given UCI section is rendered or ignored by the form section element.

The default implementation always returns true. User code or classes extending AbstractSection may override this function with custom implementations.

Parameters:
NameTypeDescription
section_idstring

The UCI section ID to test.

Returns:

Returns true when the given UCI section ID should be handled and false when it should be ignored.

Type: 
boolean

formvalue(section_id, optionopt) → {null|string|Array.<string>|Object.<string, (null|string|Array.<string>)>}

Query the underlying option widget input values.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the widget input values of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the widget input value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | string | Array.<string> | Object.<string, (null|string|Array.<string>)>

getOption(optionopt) → {null|LuCI.form.AbstractValue|Object.<string, LuCI.form.AbstractValue>}

Obtain underlying option objects.

This function is sensitive to the amount of arguments passed to it; if no option name is specified, all options within this section are returned as a dictionary.

If an option name is supplied, this function returns the matching LuCI.form.AbstractValue instance only.

Parameters:
NameTypeAttributesDescription
optionstring<optional>

The name of the option object to obtain

Returns:

Returns either a dictionary of option names and their corresponding option instance objects or just a single object instance value, depending on the amount of passed arguments.

Type: 
null | LuCI.form.AbstractValue | Object.<string, LuCI.form.AbstractValue>

getUIElement(section_id, optionopt) → {null|LuCI.ui.AbstractElement|Object.<string, (null|LuCI.ui.AbstractElement)>}

Obtain underlying option LuCI.ui widget instances.

This function is sensitive to the amount of arguments passed to it; if only one argument is specified, the LuCI.ui widget instances of all options within this section are returned as a dictionary.

If both the section ID and an option name are supplied, this function returns the LuCI.ui widget instance value of the specified option only.

Parameters:
NameTypeAttributesDescription
section_idstring

The configuration section ID

optionstring<optional>

The name of the option to query

Returns:

Returns either a dictionary of option names and their corresponding widget input values or just a single widget input value, depending on the amount of passed arguments.

Type: 
null | LuCI.ui.AbstractElement | Object.<string, (null|LuCI.ui.AbstractElement)>

load() → {Promise.<void>}

Load the configuration covered by this section.

The load() function recursively walks the section element tree and invokes the load function of each child option element.

Returns:

Returns a promise resolving once the values of all child elements have been loaded. The promise may reject with an error if any of the child elements' load functions rejected with an error.

Type: 
Promise.<void>

option(optionclass, cbiClass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to the section.

Note that taboption() should be used instead if this form section element uses tabs.

Parameters:
NameTypeAttributesDescription
optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

cbiClassobject

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

args*<repeatable>

argument array

Throws:

Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

Type
TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

parse() → {Promise.<void>}

Parse this sections form input.

The parse() function recursively walks the section element tree and triggers input value reading and validation for each encountered child option element.

Options which are hidden due to unsatisfied dependencies are skipped.

Returns:

Returns a promise resolving once the values of all child elements have been parsed. The returned promise is rejected if any parsed values do not meet the validation constraints of their respective elements.

Type: 
Promise.<void>

render() → {Node|Promise.<Node>}

Render the form element.

The render() function recursively walks the form element tree and renders the markup for each element, returning the assembled DOM tree.

Returns:

May return a DOM Node or a promise resolving to a DOM node containing the form element's markup, including the markup of any child elements.

Type: 
Node | Promise.<Node>

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

tab(name, title, descriptionopt)

Add an option tab to the section.

The child option elements of a section may be divided into multiple tabs to provide a better overview to the user.

Before options can be moved into a tab pane, the corresponding tab has to be defined first, which is done by calling this function.

Note that once tabs are defined, user code must use the taboption() method to add options to specific tabs. Option elements added by option() will not be assigned to any tab and not be rendered in this case.

Parameters:
NameTypeAttributesDescription
namestring

The name of the tab to register. It may be freely chosen and just serves as an identifier to differentiate tabs.

titlestring

The human readable caption of the tab.

descriptionstring<optional>

An additional description text for the corresponding tab pane. It is displayed as a text paragraph below the tab but before the tab pane contents. If omitted, no description will be rendered.

Throws:

Throws an exception if a tab with the same name already exists.

Type
Error

taboption(tabName, optionclass, …args) → {LuCI.form.AbstractValue}

Add a configuration option widget to a tab of the section.

Parameters:
NameTypeAttributesDescription
tabNamestring

The name of the section tab to add the option element to.

optionclassLuCI.form.AbstractValue

The option class to use for rendering the configuration option. Note that this value must be the class itself, not a class instance obtained from calling new. It must also be a class derived from AbstractSection.

args*<repeatable>

(classargs) Additional arguments which are passed as-is to the constructor of the given option class. Refer to the class specific constructor documentation for details.

Throws:
  • Throws a ReferenceError exception when the given tab name does not exist.

    Type
    ReferenceError
  • Throws a TypeError exception in case the passed class value is not a descendant of AbstractValue.

    Type
    TypeError
Returns:

Returns the instantiated option class instance.

Type: 
LuCI.form.AbstractValue

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.Value.html b/jsapi/LuCI.form.Value.html index 5b9b0d790b..41ebbcbfc1 100644 --- a/jsapi/LuCI.form.Value.html +++ b/jsapi/LuCI.form.Value.html @@ -1,3 +1,3 @@ Class: Value
On this page

LuCI.form. Value

The Value class represents a simple one-line form input using the LuCI.ui.Textfield or - in case choices are added - the LuCI.ui.Combobox class as underlying widget.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

render() → {Node|Promise.<Node>}

Render the form element.

The render() function recursively walks the form element tree and renders the markup for each element, returning the assembled DOM tree.

Returns:

May return a DOM Node or a promise resolving to a DOM node containing the form element's markup, including the markup of any child elements.

Type: 
Node | Promise.<Node>

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file +
On this page

LuCI.form. Value

The Value class represents a simple one-line form input using the LuCI.ui.Textfield or - in case choices are added - the LuCI.ui.Combobox class as underlying widget.

Extends

Members

datatype :string

Specifies a datatype constraint expression to validate input values against. Refer to LuCI.validation for details on the format.

If the user entered input does not match the datatype validation, the option element is marked as invalid.

Type:
  • string
Default Value
  • null

default :*

Sets a default value to use when the underlying UCI option is not set.

Type:
  • *
Default Value
  • null

editable :boolean

Mark the grid section option element as editable.

Options which are displayed in the table portion of a GridSection instance are rendered as readonly text by default. By setting the editable property of a child option element to true, that element is rendered as a full input widget within its cell instead of a text only preview.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • false

modalonly :boolean

Move the grid section option element into the table, the modal popup or both.

If this property is null (the default), the option element is displayed in both the table preview area and the per-section instance modal popup of a grid section. When it is set to false the option is only shown in the table but not the modal popup. When set to true, the option is only visible in the modal popup but not the table.

This property has no effect on options that are not children of grid section elements.

Type:
  • boolean
Default Value
  • null

onchange :function

Register a custom value change handler.

If this property is set to a function, it is invoked whenever the value of the underlying UI input element changes.

The invoked handler function will receive the DOM click element as first and the underlying configuration section ID as well as the input value as second and third argument respectively.

Type:
  • function
Default Value
  • null

optional :boolean

If set to true, the underlying ui input widget is allowed to be empty, otherwise the option element is marked invalid when no value is entered or selected by the user.

Type:
  • boolean
Default Value
  • false

password :boolean

If set to true, the field is rendered as a password input, otherwise as a plain text input.

Type:
  • boolean
Default Value
  • false

placeholder :string

Set a placeholder string to use when the input field is empty.

Type:
  • string
Default Value
  • null

readonly :boolean

Make option element readonly.

This property defaults to the readonly state of the parent form element. When set to true, the underlying widget is rendered in disabled state, meaning its contents cannot be changed and the widget cannot be interacted with.

Type:
  • boolean
Default Value
  • false

retain :boolean

If set to true, the underlying ui input widget value is not cleared from the configuration on unsatisfied dependencies. The default behavior is to remove the values of all options whose dependencies are not fulfilled.

Type:
  • boolean
Default Value
  • false

rmempty :boolean

If set to false, the underlying option value is retained upon saving the form when the option element is disabled due to unsatisfied dependency constraints.

Type:
  • boolean
Default Value
  • true

uciconfig :string

Override the UCI configuration name to read the option value from.

By default, the configuration name is inherited from the parent Map. By setting this property, a deviating configuration may be specified.

The default of null means inherit from the parent form.

Type:
  • string
Default Value
  • null

ucioption :string

Override the UCI option name to read the value from.

By default, the elements name, which is passed as the third argument to the constructor, is used as the UCI option name. By setting this property, a deviating UCI option may be specified.

The default of null means use the option element name.

Type:
  • string
Default Value
  • null

ucisection :string

Override the UCI section name to read the option value from.

By default, the section ID is inherited from the parent section element. By setting this property, a deviating section may be specified.

The default of null means inherit from the parent section.

Type:
  • string
Default Value
  • null

validate :function

Specifies a custom validation function to test the user input for validity. The validation function must return true to accept the value. Any other return value type is converted to a string and displayed to the user as a validation error message.

If the user entered input does not pass the validation function, the option element is marked as invalid.

Type:
  • function
Default Value
  • null

width :number|string

Override the cell width of a table or grid section child option.

If the property is set to a numeric value, it is treated as pixel width which is set on the containing cell element of the option, essentially forcing a certain column width. When the property is set to a string value, it is applied as-is to the CSS width property.

This property has no effect on options that are not children of grid or table section elements.

Type:
  • number | string
Default Value
  • null

Methods

append(obj)

Add another form element as children to this element.

Parameters:
NameTypeDescription
objAbstractElement

The form element to add.

cbid(section_id) → {string}

Obtain the internal ID ("cbid") of the element instance.

Since each form section element may map multiple underlying configuration sections, the configuration section ID is required to form a fully qualified ID pointing to the specific element instance within the given specific section.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the element ID.

Type: 
string

cfgvalue(section_id, set_value) → {*}

Query the underlying configuration value.

The default implementation of this method returns the cached return value of load(). It may be overridden by user code to obtain the configuration value in a different way.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

set_valuestring

The value to assign

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value.

Type: 
*

depends(field, valueopt)

Add a dependency constraint to the option.

Dependency constraints allow making the presence of option elements dependent on the current values of certain other options within the same form. An option element with unsatisfied dependencies will be hidden from the view and its current value omitted when saving.

Multiple constraints (that is, multiple calls to depends()) are treated as alternatives, forming a logical "or" expression.

By passing an object of name => value pairs as the first argument, it is possible to depend on multiple options simultaneously, forming a logical "and" expression.

Option names may be given in "dot notation" which allows referencing option elements outside the current form section. If a name without a dot is specified, it refers to an option within the same configuration section. If specified as configname.sectionid.optionname, options anywhere within the same form may be specified.

The object notation also allows for a number of special keys which are not treated as option names but as modifiers to influence the dependency constraint evaluation. The associated value of these special "tag" keys is ignored. The recognized tags are:

  • !reverse
    Invert the dependency, instead of requiring another option to be equal to the dependency value, that option should not be equal.
  • !contains
    Instead of requiring an exact match, the dependency is considered satisfied when the dependency value is contained within the option value.
  • !default
    The dependency is always satisfied

Examples:

  • opt.depends("foo", "test")
    Require the value of `foo` to be `test`.
  • opt.depends({ foo: "test" })
    Equivalent to the previous example.
  • opt.depends({ foo: /test/ })
    Require the value of `foo` to match the regular expression `/test/`.
  • opt.depends({ foo: "test", bar: "qrx" })
    Require the value of `foo` to be `test` and the value of `bar` to be `qrx`.
  • opt.depends({ foo: "test" })
    opt.depends({ bar: "qrx" })

    Require either foo to be set to test, or the bar option to be qrx.
  • opt.depends("test.section1.foo", "bar")
    Require the "foo" form option within the "section1" section to be set to "bar".
  • opt.depends({ foo: "test", "!contains": true })
    Require the "foo" option value to contain the substring "test".
Parameters:
NameTypeAttributesDescription
fieldstring | Object.<string, (string|RegExp)>

The name of the option to depend on or an object describing multiple dependencies which must be satisfied (a logical "and" expression).

valuestring | RegExp<optional>

When invoked with a plain option name as the first argument, this parameter specifies the expected value. In case an object is passed as the first argument, this parameter is ignored.

formvalue(section_id) → {*}

Query the current form input value.

The default implementation of this method returns the current input value of the underlying LuCI.ui widget. It may be overridden by user code to handle input values differently.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the current input value.

Type: 
*

getUIElement(section_id) → {LuCI.ui.AbstractElement|null}

Obtain the underlying LuCI.ui element instance.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the LuCI.ui element instance or null in case the form option implementation does not use LuCI.ui widgets.

Type: 
LuCI.ui.AbstractElement | null

getValidationError(section_id) → {string}

Returns the current validation error for this input.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

The validation error at this time

Type: 
string

isActive(section_id) → {boolean}

Test whether the option element is currently active.

An element is active when it is not hidden due to unsatisfied dependency constraints.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the option element currently is active, otherwise it returns false.

Type: 
boolean

isValid(section_id) → {boolean}

Test whether the input value is currently valid.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns true if the input value currently is valid, otherwise it returns false.

Type: 
boolean

load(section_id) → {*|Promise.<*>}

Load the underlying configuration value.

The default implementation of this method reads and returns the underlying UCI option value (or the related JavaScript property for JSONMap instances). It may be overridden by user code to load data from non-standard sources.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the configuration value to initialize the option element with. The return value of this function is filtered through Promise.resolve() so it may return promises if overridden by user code.

Type: 
* | Promise.<*>

parse(section_id) → {Promise.<void>}

Parse the option element input.

The function is invoked when the parse() method has been invoked on the parent form and triggers input value reading and validation.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Returns:

Returns a promise resolving once the input value has been read and validated or rejecting in case the input value does not meet the validation constraints.

Type: 
Promise.<void>

remove(section_id)

Remove the corresponding value from the configuration.

This function is invoked upon saving the parent form when the option element has been hidden due to unsatisfied dependencies or when the user cleared the input value and the option is marked optional.

The default implementation simply removes the associated option from the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative removal logic, e.g. to retain the original value.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

render() → {Node|Promise.<Node>}

Render the form element.

The render() function recursively walks the form element tree and renders the markup for each element, returning the assembled DOM tree.

Returns:

May return a DOM Node or a promise resolving to a DOM node containing the form element's markup, including the markup of any child elements.

Type: 
Node | Promise.<Node>

stripTags(s) → {string}

Strip any HTML tags from the given input string, and decode HTML entities.

Parameters:
NameTypeDescription
sstring

The input string to clean.

Returns:

The cleaned input string with HTML tags removed, and HTML entities decoded.

Type: 
string

textvalue(section_id) → {string}

Obtain a textual input representation.

The default implementation of this method returns the HTML-escaped current input value of the underlying LuCI.ui widget. User code or specific option element implementations may override this function to apply a different logic, e.g. to return Yes or No depending on the checked state of checkbox elements.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

Throws:

Throws a TypeError exception when no section_id was specified.

Type
TypeError
Returns:

Returns the text representation of the current input value.

Type: 
string

titleFn(attr, …args) → {string|null}

Format the given named property as a title string.

This function looks up the given named property and formats its value suitable for use as an element caption or description string. It also strips any HTML tags from the result.

If the property value is a string, it is passed to String.format() along with any additional parameters passed to titleFn().

If the property value is a function, it is invoked with any additional titleFn() parameters as arguments, and the obtained return value is converted to a string.

In all other cases, null is returned.

Parameters:
NameTypeAttributesDescription
attrstring

(property) The name of the element property to use.

argsstring<repeatable>

(fmt_args) Extra values to format the title string with.

Returns:

The formatted title string or null if the property did not exist or was neither a string nor a function.

Type: 
string | null

value(key, val)

Add a predefined choice to the form option. By adding one or more choices, the plain text input field is turned into a combobox widget which prompts the user to select a predefined choice, or to enter a custom value.

Parameters:
NameTypeDescription
keystring

The choice value to add.

valNode | string

The caption for the choice value. May be a DOM node, a document fragment or a plain text string. If omitted, the key value is used as a caption.

write(section_id, formvalue) → {null}

Write the current input value into the configuration.

This function is invoked upon saving the parent form when the option element is valid and when its input value has been changed compared to the initial value returned by cfgvalue().

The default implementation simply sets the given input value in the UCI configuration (or the associated JavaScript object property in case of JSONMap forms). It may be overridden by user code to implement alternative save logic, e.g. to transform the input value before it is written.

Parameters:
NameTypeDescription
section_idstring

The configuration section ID

formvaluestring | Array.<string>

The input value to write.

Returns:
Type: 
null
LuCI Documentation
\ No newline at end of file diff --git a/jsapi/LuCI.form.html b/jsapi/LuCI.form.html index 782fcbdc03..acbfce18f3 100644 --- a/jsapi/LuCI.form.html +++ b/jsapi/LuCI.form.html @@ -1,6 +1,6 @@ Class: form
On this page

LuCI. form

The LuCI form class provides high level abstractions for creating UCI- or JSON backed configurations forms.

To import the class in views, use 'require form', to import it in external JavaScript, use L.require("form").then(...).

A typical form is created by first constructing a LuCI.form.Map or LuCI.form.JSONMap instance using new and by subsequently adding sections and options to it. Finally render() is invoked on the instance to assemble the HTML markup and insert it into the DOM.

Example
'use strict';
+    
On this page

LuCI. form

The LuCI form class provides high level abstractions for creating UCI- or JSON backed configurations forms.

To import the class in views, use 'require form', to import it in external JavaScript, use L.require("form").then(...).

A typical form is created by first constructing a LuCI.form.Map or LuCI.form.JSONMap instance using new and by subsequently adding sections and options to it. Finally render() is invoked on the instance to assemble the HTML markup and insert it into the DOM.

Example
'use strict';
 'require form';
 
 let m, s, o;
diff --git a/jsapi/form.js.html b/jsapi/form.js.html
index d479e903e3..c5ba3229ea 100644
--- a/jsapi/form.js.html
+++ b/jsapi/form.js.html
@@ -2151,7 +2151,7 @@ const CBIAbstractValue = CBIAbstractElement.extend(/** @lends LuCI.form.Abstract
 			const cval = this.cfgvalue(section_id);
 			const fval = this.formvalue(section_id);
 
-			if (fval == null || fval == '') {
+			if (fval == null || fval == '' || (fval == this.default && (this.optional || this.rmempty))) {
 				if (this.rmempty || this.optional) {
 					return Promise.resolve(this.remove(section_id));
 				}
@@ -2163,11 +2163,7 @@ const CBIAbstractValue = CBIAbstractElement.extend(/** @lends LuCI.form.Abstract
 				}
 			}
 			else if (this.forcewrite || !isEqual(cval, fval)) {
-				/*
-				 * do not remove elements that are not rendered yet
-				 */
-				if (this.map.findElement('data-field', this.cbid(section_id)) != null)
-					return Promise.resolve(this.write(section_id, fval));
+				return Promise.resolve(this.write(section_id, fval));
 			}
 		}
 		else if (!this.retain) {