diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2016-01-15 16:39:01 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2016-01-15 16:39:15 +0100 |
commit | eaf961fa70fdb39cc84d67d2512c2daea9207b69 (patch) | |
tree | 58b629df76b234d081a70ba974214ec106cee2e5 /modules/luci-base/luasrc | |
parent | ad064f0b039839dd333bfe8e9631cbc5218410b0 (diff) |
luci-base: initialize CBI optionals on initial Map render (#618)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'modules/luci-base/luasrc')
-rw-r--r-- | modules/luci-base/luasrc/cbi.lua | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/modules/luci-base/luasrc/cbi.lua b/modules/luci-base/luasrc/cbi.lua index 2c1bb4d226..2f97539ab3 100644 --- a/modules/luci-base/luasrc/cbi.lua +++ b/modules/luci-base/luasrc/cbi.lua @@ -336,7 +336,7 @@ function Map.__init__(self, config, ...) end function Map.formvalue(self, key) - return self.readinput and luci.http.formvalue(key) + return self.readinput and luci.http.formvalue(key) or nil end function Map.formvaluetable(self, key) @@ -886,14 +886,18 @@ function AbstractSection.render_tab(self, tab, ...) end -- Parse optional options -function AbstractSection.parse_optionals(self, section) +function AbstractSection.parse_optionals(self, section, noparse) if not self.optional then return end self.optionals[section] = {} - local field = self.map:formvalue("cbi.opt."..self.config.."."..section) + local field = nil + if not noparse then + field = self.map:formvalue("cbi.opt."..self.config.."."..section) + end + for k,v in ipairs(self.children) do if v.optional and not v:cfgvalue(section) and not self:has_tabs() then if field == v.option then @@ -1071,6 +1075,11 @@ function NamedSection.__init__(self, map, section, stype, ...) self.section = section end +function NamedSection.prepare(self) + AbstractSection.prepare(self) + AbstractSection.parse_optionals(self, self.section, true) +end + function NamedSection.parse(self, novld) local s = self.section local active = self:cfgvalue(s) @@ -1120,6 +1129,15 @@ function TypedSection.__init__(self, map, type, ...) self.anonymous = false end +function TypedSection.prepare(self) + AbstractSection.prepare(self) + + local i, s + for i, s in ipairs(self:cfgsections()) do + AbstractSection.parse_optionals(self, s, true) + end +end + -- Return all matching UCI sections for this TypedSection function TypedSection.cfgsections(self) local sections = {} |