projects
/
project
/
luci.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
libs/cbi: Prevent SimpleForms from prematurely parsing form data
[project/luci.git]
/
libs
/
cbi
/
luasrc
/
cbi.lua
diff --git
a/libs/cbi/luasrc/cbi.lua
b/libs/cbi/luasrc/cbi.lua
index 8816b11b7bafe0b702a44b0a3d0a7c34542edf43..9996c8418dc27962d630d4ec41273c3d52194ec0 100644
(file)
--- a/
libs/cbi/luasrc/cbi.lua
+++ b/
libs/cbi/luasrc/cbi.lua
@@
-260,7
+260,9
@@
function SimpleForm.__init__(self, config, title, description, data)
end
function SimpleForm.parse(self, ...)
end
function SimpleForm.parse(self, ...)
- Node.parse(self, 1, ...)
+ if luci.http.formvalue("cbi.submit") then
+ Node.parse(self, 1, ...)
+ end
local valid = true
for i, v in ipairs(self.children) do
local valid = true
for i, v in ipairs(self.children) do
@@
-287,6
+289,7
@@
end
function SimpleForm.field(self, class, ...)
if instanceof(class, AbstractValue) then
local obj = class(self, ...)
function SimpleForm.field(self, class, ...)
if instanceof(class, AbstractValue) then
local obj = class(self, ...)
+ obj.track_missing = true
self:append(obj)
return obj
else
self:append(obj)
return obj
else
@@
-616,6
+619,7
@@
function AbstractValue.__init__(self, map, option, ...)
self.tag_missing = {}
self.deps = {}
self.tag_missing = {}
self.deps = {}
+ self.track_missing = false
self.rmempty = false
self.default = nil
self.size = nil
self.rmempty = false
self.default = nil
self.size = nil
@@
-653,18
+657,18
@@
function AbstractValue.parse(self, section)
local cvalue = self:cfgvalue(section)
if fvalue and fvalue ~= "" then -- If we have a form value, write it to UCI
local cvalue = self:cfgvalue(section)
if fvalue and fvalue ~= "" then -- If we have a form value, write it to UCI
- fvalue = self:transform(self:validate(fvalue))
+ fvalue = self:transform(self:validate(fvalue
, section
))
if not fvalue then
self.tag_invalid[section] = true
end
if not fvalue then
self.tag_invalid[section] = true
end
- if fvalue and not (fvalue ==
self:cfgvalue(section)
) then
+ if fvalue and not (fvalue ==
cvalue
) then
self:write(section, fvalue)
end
else -- Unset the UCI or error
if self.rmempty or self.optional then
self:remove(section)
self:write(section, fvalue)
end
else -- Unset the UCI or error
if self.rmempty or self.optional then
self:remove(section)
- elseif not fvalue or fvalue ~= cvalue then
-
--
self.tag_missing[section] = true
+ elseif
self.track_missing and
not fvalue or fvalue ~= cvalue then
+ self.tag_missing[section] = true
end
end
end
end
end
end