I have copied this from https://github.com/openwrt/luci/wiki/CBI so that I may freely annotate it as necessary Writing LuCI CBI modelsCBI models are Lua files describing the structure of an UCI config file and the resulting HTML form to be evaluated by the CBI parser. All CBI model files must return an object of type luci.cbi.Map. For a commented example of a CBI model, see the Writing Modules tutorial. The scope of a CBI model file is automatically extended by the contents of the module luci.cbi and the translate function from luci.i18n This Reference covers the basics of the CBI system. class Map (config, title, description)This is the root object of the model.
:section (sectionclass, ...)Creates a new section
class NamedSection (name, type, title, description)An object describing an UCI section selected by the name. Use Map:section(NamedSection, ''name'', ''type'', ''title'', ''description'') to instantiate.
.addremove = falseAllows the user to remove and recreate the configuration section .dynamic = falseMarks this section as dynamic. Dynamic sections can contain an undefinded number of completely userdefined options. .optional = trueParse optional options :option (optionclass, ...)Creates a new option
class TypedSection (type, title, description)An object describing a group of UCI sections selected by their type. Use Map:section(TypedSection, ''type'', ''title'', ''description'') to instantiate.
.addremove = falseAllows the user to remove and recreate the configuration section .dynamic = falseMarks this section as dynamic. Dynamic sections can contain an undefinded number of completely userdefined options. .optional = trueParse optional options .anonymous = falseDo not show section names :depends (key, value)Only select those sections where the option key == value .filter (self, section) [abstract]You can override this function to filter certain sections that will not be parsed. The filter function will be called for every section that should be parsed and returns nil for sections that should be filtered. For all other sections it should return the section name as given in the second parameter. :option (optionclass, ...)Creates a new option
class Value (option, title, description)An object describing an option in a section of a UCI File. Creates a standard text field in the formular. Use NamedSection:option(Value, ''option'', ''title'', ''description'') or TypedSection:option(Value, ''option'', ''title'', ''description'') to instantiate.
.password = trueThis is a password field .default = nilThe default value .maxlength = nilThe maximum length of the value. a length validation .optional = falseMarks this option as optional, implies .rmempty = true .rmempty = trueRemoves this option from the configuration file when the user enters an empty value .size = nilThe size of the form field. ie: how long should the field be (rarely used) :value (key, value = key)Convert this text field into a combobox if possible and add a selection option. :depends (key, value)Only show this option field if another option key is set to value in the same section. class ListValue (option, title, description)An object describing an option in a section of a UCI File. Creates a list box in the formular. Use NamedSection:option(ListValue, ''option'', ''title'', ''description'') or TypedSection:option(ListValue, ''option'', ''title'', ''description'') to instantiate.
.default = nilThe default value .optional = falseMarks this option as optional, implies .rmempty = true .rmempty = trueRemoves this option from the configuration file when the user enters an empty value .size = nilThe size of the form field .widget = "select"Selects the form widget to be used: "select" or "radio" :depends (key, value)Only show this option field if another option key is set to value in the same section. :value (key, value = key)Adds an entry to the selection list class Flag (option, title, description)An object describing an option with two possible values in a section of a UCI File. Creates a checkbox field in the formular. Use NamedSection:option(Flag, ''option'', ''title'', ''description'') or TypedSection:option(Flag, ''option'', ''title'', ''description'') to instantiate.
.default = nilThe default value .disabled = 0The value that should be set if the checkbox is unchecked .enabled = 1The value that should be set if the checkbox is checked .optional = falseMarks this option as optional, implies .rmempty = true .rmempty = trueRemoves this option from the configuration file when the user enters an empty value .size = nilThe size of the form field :depends (key, value)Only show this option field if another option key is set to value in the same section. class MultiValue (option, title, description)An object describing an option in a section of a UCI File. Creates several checkboxed as form fields. Use NamedSection:option(MultiValue, ''option'', ''title'', ''description'') or TypedSection:option(MultiValue, ''option'', ''title'', ''description'') to instantiate.
.default = nilThe default value .delimiter = " "The string which will be used to delimit the values .optional = falseMarks this option as optional, implies .rmempty = true .rmempty = trueRemoves this option from the configuration file when the user enters an empty value .size = nilThe size of the form field .widget = "checkbox"Selects the form widget to be used: "checkbox" or "select" :depends (key, value)Only show this option field if another option key is set to value in the same section. :value (key, value = key)Adds an entry to the checkbox list class DummyValue (option, title, description)An object describing an option in a section of a UCI File. Creates a readonly field in the form. Use NamedSection:option(DummyValue, ''option'', ''title'', ''description'') or TypedSection:option(DummyValue, ''option'', ''title'', ''description'') to instantiate.
:depends (key, value)Only show this option field if another option key is set to value in the same section. class TextValue (option, title, description)An object describing a multi-line textbox in a section in a non-UCI form. class Button (option, title, description)An object describing a Button in a section in a non-UCI form. class StaticList (option, title, description)Similar to the MultiValue, but stores selected Values into a UCI list instead of a space-separated string. class DynamicList (option, title, description)A list of user-defined values. |