Class: GridSection

LuCI.form. GridSection

The GridSection class maps all or - if filter() is overwritten - 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 explicitely made writable 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.

new LuCI.form.GridSection(form, section_type, title, description)

Name Type Description
form LuCI.form.Map | LuCI.form.JSONMap

The configuration form this section is added to. It is automatically passed by section().

section_type string

The type of the UCI section to map.

title string optional

The title caption of the form section element.

description string optional

The description text of the form section element.

Extends

Members

addbtntitlestring function

Override the caption used for the section add button at the bottom of the section form element. If set to a string, it will be used as-is, if set to a function, the function will be invoked and its return value is used as caption, after converting it to a string. If this property is not set, the default is Add.

Default Value:
  • null

addremoveboolean

If set to true, the user may add or remove instances from the form section widget, otherwise only preexisting sections may be edited. The default is false.

Default Value:
  • false

anonymousboolean

If set to true, mapped section instances are treated as anonymous UCI sections, which means that section instance elements will be rendered without title element and that no name is required when adding new sections. The default is false.

Default Value:
  • false

exteditstring function

Enables a per-section instance row Edit button which triggers a certain action when clicked. If set to a string, the string value is used as String.format() pattern with the name of the underlying UCI section as first format argument. The result is then interpreted as URL which LuCI will navigate to when the user clicks the edit button.

If set to a function, this function will be registered as click event handler on the rendered edit button, receiving the section instance name as first and the DOM click event as second argument.

Default Value:
  • null

max_colsnumber

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.

Default Value:
  • null

modaltitlestring function

Override the per-section instance modal popup title caption shown when clicking the More… button in a section specifying max_cols. If set to a string, it will be used as String.format() pattern with the name of the underlying UCI section as first argument, if set to a function, the function will be invoked with the section name as first argument and its return value is used as caption, after converting it to a string. If this property is not set, the default is the name of the underlying UCI configuration section.

Default Value:
  • null

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.

rowcolorsboolean

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

Default Value:
  • false

sectiontitlestring function

Override the per-section instance title caption shown in the first column of the table unless anonymous is set to true. If set to a string, it will be used as String.format() pattern with the name of the underlying UCI section as first argument, if set to a function, the function will be invoked with the section name as first argument and its return value is used as caption, after converting it to a string. If this property is not set, the default is the name of the underlying UCI configuration section.

Default Value:
  • null

sortableboolean

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

Default Value:
  • false

tabbedboolean

When set to true, instead of rendering section instances one below another, treat each instance as 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.

Default Value:
  • false

uciconfigstring

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 is null, means inheriting from the parent form.

Default Value:
  • null

Methods

inherited abstractaddModalOptions(modalSection, section_id, ev){*|Promise.<*>}

Add further options to the per-section instanced modal popup.

This function may be overwritten 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.

Name Type Description
modalSection LuCI.form.NamedSection

The NamedSection instance about to be rendered in the modal popup.

section_id string

The ID of the underlying UCI section the modal popup belongs to.

ev Event

The DOM event emitted by clicking the More… button.

Returns:
Type Description
* | Promise.<*> 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 asynchroneous work before the modal dialog is shown.

inherited append(element)

Add another form element as children to this element.

Name Type Description
element AbstractElement

The form element to add.

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

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

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

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

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

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