function Node._run_hook(self, hook)
if type(self[hook]) == "function" then
return self[hook](self)
- end
+ end
end
function Node._run_hooks(self, ...)
function Map.render(self, ...)
self:_run_hooks("on_init")
Node.render(self, ...)
- if self._apply then
+ if false and self._apply then
local fp = self._apply()
fp:read("*a")
fp:close()
return FORM_DONE
end
end
-
+
if not Map.formvalue(self, "cbi.delg.current") then
self:_run_hooks("on_init")
end
self.current = self.current or self:get_active()
self.active = self.active or self:get(self.current)
assert(self.active, "Invalid state")
-
+
local stat = FORM_DONE
if type(self.active) ~= "function" then
self.active:populate_delegator(self)
- stat = self.active:parse()
+ stat = self.active:parse()
else
self:active()
end
elseif stat < FORM_PROCEED then
return stat
end
-
+
if not Map.formvalue(self, "cbi.submit") then
return FORM_NODATA
- elseif stat > FORM_PROCEED
+ elseif stat > FORM_PROCEED
and (not newcurrent or not self:get(newcurrent)) then
return self:_run_hook("on_done") or FORM_DONE
else
}
end
+-- Check whether the section has tabs
+function AbstractSection.has_tabs(self)
+ return (self.tabs ~= nil) and (next(self.tabs) ~= nil)
+end
+
-- Appends a new option
function AbstractSection.option(self, class, option, ...)
if instanceof(class, AbstractValue) then
local field = self.map:formvalue("cbi.opt."..self.config.."."..section)
for k,v in ipairs(self.children) do
- if v.optional and not v:cfgvalue(section) then
+ if v.optional and not v:cfgvalue(section) and not self:has_tabs() then
if field == v.option then
field = nil
self.map.proceed = true
table.insert(self.section.error[section], "invalid")
else
self.section.error = {[section] = {"invalid"}}
- end
+ end
self.map.save = false
end
if fvalue and not (fvalue == cvalue) then
-- Render if this value exists or if it is mandatory
function AbstractValue.render(self, s, scope)
- if not self.optional or self:cfgvalue(s) or self:formcreated(s) then
+ if not self.optional or self.section:has_tabs() or self:cfgvalue(s) or self:formcreated(s) then
scope = scope or {}
scope.section = s
scope.cbid = self:cbid(s)
-- Validate the form value
function AbstractValue.validate(self, value)
if self.datatype and value and datatypes[self.datatype] then
- if datatypes[self.datatype](value) then
- return value
+ if type(value) == "table" then
+ local v
+ for _, v in ipairs(value) do
+ if v and #v > 0 and not datatypes[self.datatype](v) then
+ return nil
+ end
+ end
+ else
+ if not datatypes[self.datatype](value) then
+ return nil
+ end
end
- else
- return value
end
+ return value
end
AbstractValue.transform = AbstractValue.validate