1 CBI models are Lua files describing the structure of an UCI config file and the resulting HTML form to be evaluated by the CBI parser.
2 All CBI model files must return an object of type *luci.cbi.Map*. For a commented example of a CBI model, see the [[Documentation/ModulesHowTo#CBImodels|Writing Modules tutorial]].
4 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
6 This Reference covers *the basics* of the CBI system.
10 # class Map (_config'', ''title'', ''description_)
11 This is the root object of the model.
12 * *config*: configuration name to be mapped, see uci documentation and the files in /etc/config
13 * *title*: title shown in the UI
14 * *description*: description shown in the UI
16 ## :section (_sectionclass_, ...)
18 * *sectionclass*: a class object of the section
19 * _additional parameters passed to the constructor of the section class_
23 # class NamedSection (_name'', ''type'', ''title'', ''description_)
24 An object describing an UCI section selected by the name.
25 Use [[#A.3Asection.28.27.27sectionclass.27.27.2C....29|Map:section(NamedSection, _name'', ''type'', ''title'', ''description_)]] to instantiate.
26 * *name*: section name
27 * *type*: section type
28 * *title*: The title shown in the UI
29 * *description*: description shown in the UI
32 Allows the user to remove and recreate the configuration section
35 Marks this section as dynamic. Dynamic sections can contain an undefinded number of completely userdefined options.
38 Parse optional options
41 ## :option (_optionclass_, ...)
43 * *optionclass*: a class object of the section
44 * _additional parameters passed to the constructor of the option class_
48 # class TypedSection (_type'', ''title'', ''description_)
49 An object describing a group of UCI sections selected by their type.
50 Use [[#A.3Asection.28.27.27sectionclass.27.27.2C....29|Map:section(TypedSection, _type'', ''title'', ''description_)]] to instantiate.
51 * *type*: section type
52 * *title*: The title shown in the UI
53 * *description*: description shown in the UI
56 Allows the user to remove and recreate the configuration section
59 Marks this section as dynamic. Dynamic sections can contain an undefinded number of completely userdefined options.
62 Parse optional options
65 Do not show section names
68 ## :depends (_key'', ''value_)
69 Only select those sections where the option _key'' == ''value_<br />
70 If you call this function several times the dependencies will be linked with *or*
72 ## .filter (_self'', ''section_) [abstract]
73 You can override this function to filter certain sections that will not be parsed.
74 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.
76 ## :option (_optionclass_, ...)
78 _optionclass_: a class object of the section
79 additional parameters passed to the constructor of the option class
83 # class Value (_option'', ''title'', ''description_)
84 An object describing an option in a section of a UCI File. Creates a standard text field in the formular.
85 Use [[#A.3Aoption.28.27.27optionclass.27.27.2C....29|NamedSection:option(Value, _option'', ''title'', ''description'')]] or [[#A.3Aoption.28.27.27optionclass.27.27.2C....29-1|TypedSection:option(Value, ''option'', ''title'', ''description_)]] to instantiate.
86 * *option*: section name
87 * *title*: The title shown in the UI
88 * *description*: description shown in the UI
94 The maximum length of the value
97 Marks this option as optional, implies .rmempty = true
100 Removes this option from the configuration file when the user enters an empty value
103 The size of the form field
105 ## :value (_key'', ''value'' = ''key_)
106 Convert this text field into a combobox if possible and add a selection option.
109 ## :depends (_key'', ''value_)
110 Only show this option field if another option _key'' is set to ''value_ in the same section.<br />
111 If you call this function several times the dependencies will be linked with *or*
115 # class ListValue (_option'', ''title'', ''description_)
116 An object describing an option in a section of a UCI File. Creates a list box in the formular.
117 Use [[#A.3Aoption.28.27.27optionclass.27.27.2C....29|NamedSection:option(Value, _option'', ''title'', ''description'')]] or [[#A.3Aoption.28.27.27optionclass.27.27.2C....29-1|TypedSection:option(Value, ''option'', ''title'', ''description_)]] to instantiate.
118 * *option*: section name
119 * *title*: The title shown in the UI
120 * *description*: description shown in the UI
127 Marks this option as optional, implies .rmempty = true
130 Removes this option from the configuration file when the user enters an empty value
133 The size of the form field
135 ## .widget = "select"
136 selects the form widget to be used
139 ## :depends (_key'', ''value_)
140 Only show this option field if another option _key'' is set to ''value_ in the same section.<br />
141 If you call this function several times the dependencies will be linked with *or*
143 ## :value (_key'', ''value'' = ''key_)
144 Adds an entry to the selection list
148 # class Flag (_option'', ''title'', ''description_)
149 An object describing an option with two possible values in a section of a UCI File. Creates a checkbox field in the formular.
150 Use [[#A.3Aoption.28.27.27optionclass.27.27.2C....29|NamedSection:option(Value, _option'', ''title'', ''description'')]] or [[#A.3Aoption.28.27.27optionclass.27.27.2C....29-1|TypedSection:option(Value, ''option'', ''title'', ''description_)]] to instantiate.
151 * *option*: section name
152 * *title*: The title shown in the UI
153 * *description*: description shown in the UI
159 the value that shoudl be set if the checkbox is unchecked
162 the value that should be set if the checkbox is checked
165 Marks this option as optional, implies .rmempty = true
168 Removes this option from the configuration file when the user enters an empty value
171 The size of the form field
174 ## :depends (_key'', ''value_)
175 Only show this option field if another option _key'' is set to ''value_ in the same section.<br />
176 If you call this function several times the dependencies will be linked with *or*
180 # class MultiValue (_option'', ''title'', ''description_)
181 An object describing an option in a section of a UCI File. Creates several checkboxed as form fields.
182 Use [[#A.3Aoption.28.27.27optionclass.27.27.2C....29|NamedSection:option(Value, _option'', ''title'', ''description'')]] or [[#A.3Aoption.28.27.27optionclass.27.27.2C....29-1|TypedSection:option(Value, ''option'', ''title'', ''description_)]] to instantiate.
183 * *option*: section name
184 * *title*: The title shown in the UI
185 * *description*: description shown in the UI
192 The string which will be used to delimit the values
195 Marks this option as optional, implies .rmempty = true
198 Removes this option from the configuration file when the user enters an empty value
201 The size of the form field
203 ## .widget = "checkbox"
204 selects the form widget to be used
207 ## :depends (_key'', ''value_)
208 Only show this option field if another option _key'' is set to ''value_ in the same section.<br />
209 If you call this function several times the dependencies will be linked with *or*
211 ## :value (_key'', ''value'' = ''key_)
212 Adds an entry to the checkbox list
216 # class DummyValue (_option'', ''title'', ''description_)
217 An object describing an option in a section of a UCI File. Creates a readonly field in the form.
218 Use [[#A.3Aoption.28.27.27optionclass.27.27.2C....29|NamedSection:option(Value, _option'', ''title'', ''description'')]] or [[#A.3Aoption.28.27.27optionclass.27.27.2C....29-1|TypedSection:option(Value, ''option'', ''title'', ''description_)]] to instantiate.
219 * *option*: section name
220 * *title*: The title shown in the UI
221 * *description*: description shown in the UI
225 ## :depends (_key'', ''value_)
226 Only show this option field if another option _key'' is set to ''value_ in the same section.<br />
227 If you call this function several times the dependencies will be linked with *or*
232 # class TextValue (_option'', ''title'', ''description_)
233 An object describing a multi-line textbox in a section in a non-UCI form.
237 # class Button (_option'', ''title'', ''description_)
238 An object describing a Button in a section in a non-UCI form.
242 # class StaticList (_option'', ''title'', ''description_)
243 Similar to the MultiValue, but stores selected Values into a UCI list instead of a space-separated string.
247 # class DynamicList (_option'', ''title'', ''description_)
248 A list of user-defined values.