summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base
diff options
context:
space:
mode:
authorChristian Schoenebeck <christian.schoenebeck@gmail.com>2015-10-30 18:42:38 +0100
committerChristian Schoenebeck <christian.schoenebeck@gmail.com>2015-10-30 18:42:38 +0100
commit84a57ec36f62fac2484b3ab2dc0380321e86aefe (patch)
tree9fc099f4b5520af218dcccf25b3006b44e8032b5 /modules/luci-base
parent25a44579e53e177bff37d1ce0f875bfa4ec89edd (diff)
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>
Diffstat (limited to 'modules/luci-base')
-rw-r--r--modules/luci-base/luasrc/cbi.lua20
1 files changed, 15 insertions, 5 deletions
diff --git a/modules/luci-base/luasrc/cbi.lua b/modules/luci-base/luasrc/cbi.lua
index a0090958f..1aa00eed9 100644
--- a/modules/luci-base/luasrc/cbi.lua
+++ b/modules/luci-base/luasrc/cbi.lua
@@ -1528,17 +1528,25 @@ function Flag.__init__(self, ...)
end
-- 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(
FEXIST_PREFIX .. self.config .. "." .. section .. "." .. self.option)
if fexists then
local fvalue = self:formvalue(section) and self.enabled or self.disabled
local cvalue = self:cfgvalue(section)
- if fvalue ~= self.default or (not self.optional and not self.rmempty) then
- self:write(section, fvalue)
- else
+ local val_err
+ fvalue, val_err = self:validate(fvalue, section)
+ 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)
+ else
+ self:write(section, fvalue)
end
if (fvalue ~= cvalue) then self.section.changed = true end
else
@@ -1550,7 +1558,9 @@ end
function Flag.cfgvalue(self, section)
return AbstractValue.cfgvalue(self, section) or self.default
end
-
+function Flag.validate(self, value)
+ return value
+end
--[[
ListValue - A one-line value predefined in a list