cbi.lua: Implement Flag.validate function
cbi.lua - Implement Flag.validate function to be overwritable - rewritten if clause for easier reading ;-) Signed-off-by: Christian Schoenebeck <christian.schoenebeck@gmail.com>
This commit is contained in:
parent
25a44579e5
commit
84a57ec36f
1 changed files with 15 additions and 5 deletions
|
@ -1528,17 +1528,25 @@ function Flag.__init__(self, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- A flag can only have two states: set or unset
|
-- A flag can only have two states: set or unset
|
||||||
function Flag.parse(self, section)
|
function Flag.parse(self, section, novld)
|
||||||
local fexists = self.map:formvalue(
|
local fexists = self.map:formvalue(
|
||||||
FEXIST_PREFIX .. self.config .. "." .. section .. "." .. self.option)
|
FEXIST_PREFIX .. self.config .. "." .. section .. "." .. self.option)
|
||||||
|
|
||||||
if fexists then
|
if fexists then
|
||||||
local fvalue = self:formvalue(section) and self.enabled or self.disabled
|
local fvalue = self:formvalue(section) and self.enabled or self.disabled
|
||||||
local cvalue = self:cfgvalue(section)
|
local cvalue = self:cfgvalue(section)
|
||||||
if fvalue ~= self.default or (not self.optional and not self.rmempty) then
|
local val_err
|
||||||
self:write(section, fvalue)
|
fvalue, val_err = self:validate(fvalue, section)
|
||||||
else
|
if not fvalue then
|
||||||
|
if not novld then
|
||||||
|
self:add_error(section, "invalid", val_err)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if fvalue == self.default and (self.optional or self.rmempty) then
|
||||||
self:remove(section)
|
self:remove(section)
|
||||||
|
else
|
||||||
|
self:write(section, fvalue)
|
||||||
end
|
end
|
||||||
if (fvalue ~= cvalue) then self.section.changed = true end
|
if (fvalue ~= cvalue) then self.section.changed = true end
|
||||||
else
|
else
|
||||||
|
@ -1550,7 +1558,9 @@ end
|
||||||
function Flag.cfgvalue(self, section)
|
function Flag.cfgvalue(self, section)
|
||||||
return AbstractValue.cfgvalue(self, section) or self.default
|
return AbstractValue.cfgvalue(self, section) or self.default
|
||||||
end
|
end
|
||||||
|
function Flag.validate(self, value)
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
ListValue - A one-line value predefined in a list
|
ListValue - A one-line value predefined in a list
|
||||||
|
|
Loading…
Reference in a new issue