Class: form
LuCI. form
The LuCI form class provides high level abstractions for creating 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'; var m, s, o; m = new form.Map('example', 'Example form', 'This is an example form mapping the contents of /etc/config/example'); s = m.section(form.NamedSection, 'first_section', 'example', 'The first section', 'This sections maps "config example first_section" of /etc/config/example'); o = s.option(form.Flag, 'some_bool', 'A checkbox option'); o = s.option(form.ListValue, 'some_choice', 'A select element'); o.value('choice1', 'The first choice'); o.value('choice2', 'The second choice'); m.render().then(function(node) { document.body.appendChild(node); });