Class: AbstractSection

LuCI.form. AbstractSection

The AbstractSection class serves as abstract base for the different form section styles implemented by LuCI.form. It provides the common logic for enumerating underlying configuration section instances, for registering form options and for handling tabs to segment child options.

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

new LuCI.form.AbstractSection()

Extends

Members

readonlyparentoptionLuCI.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.

Methods

inherited append(element)

Add another form element as children to this element.

Name Type Description
element AbstractElement

The form element to add.

abstractcfgsections(){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:
Type Description
Array.<string> 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.

abstractfilter(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 overwrite this function with custom implementations.

Name Type Description
section_id string

The UCI section ID to test.

Returns:
Type Description
boolean Returns true when the given UCI section ID should be handled and false when it should be ignored.

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:
Type Description
Promise.<void> 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.

option(optionclass, classargs){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.

Name Type Description
optionclass LuCI.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 dervied from LuCI.form.AbstractSection.

classargs * repeatable

Additional arguments which are passed as-is to the contructor of the given option class. Refer to the class specific constructor documentation for details.

Throws:

Throws a TypeError exception in case the passed class value is not a descendent of AbstractValue.

Type
TypeError
Returns:
Type Description
LuCI.form.AbstractValue Returns the instantiated option class instance.

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 unsatisified dependencies are skipped.

Returns:
Type Description
Promise.<void> Returns a promise resolving once the values of all child elements have been parsed. The returned promise is rejected if any parsed values are not meeting the validation constraints of their respective elements.

inherited abstractrender(){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:
Type Description
Node | Promise.<Node> 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.

inherited stripTags(input){string}

Strip any HTML tags from the given input string.

Name Type Description
input string

The input string to clean.

Returns:
Type Description
string The cleaned input string with HTML removes removed.

tab(name, title, description)

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.

Name Type Description
name string

The name of the tab to register. It may be freely chosen and just serves as an identifier to differentiate tabs.

title string

The human readable caption of the tab.

description string optional

An additional description text for the corresponding tab pane. It is displayed as text paragraph below the tab but before the tab pane contents. If omitted, no description will be rendered.

Throws:

Throws an exeption if a tab with the same name already exists.

Type
Error

taboption(tabname, optionclass, classargs){LuCI.form.AbstractValue}

Add a configuration option widget to a tab of the section.

Name Type Description
tabname string

The name of the section tab to add the option element to.

optionclass LuCI.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 dervied from LuCI.form.AbstractSection.

classargs * repeatable

Additional arguments which are passed as-is to the contructor 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 descendent of AbstractValue.

    Type
    TypeError
Returns:
Type Description
LuCI.form.AbstractValue Returns the instantiated option class instance.

inherited titleFn(property, fmt_args){string|null}

Format the given named property as title string.

This function looks up the given named property and formats its value suitable for use as 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.

Name Type Description
property string

The name of the element property to use.

fmt_args * repeatable

Extra values to format the title string with.

Returns:
Type Description
string | null The formatted title string or null if the property did not exist or was neither a string nor a function.