libs/cbi: Create section after validation to avoid validation errors with empty fields
This commit is contained in:
parent
ccf73ec14e
commit
7e792dad2e
1 changed files with 30 additions and 28 deletions
|
@ -699,35 +699,9 @@ end
|
||||||
|
|
||||||
function TypedSection.parse(self)
|
function TypedSection.parse(self)
|
||||||
if self.addremove then
|
if self.addremove then
|
||||||
-- Create
|
|
||||||
local crval = CREATE_PREFIX .. self.config .. "." .. self.sectiontype
|
|
||||||
local name = luci.http.formvalue(crval)
|
|
||||||
if self.anonymous then
|
|
||||||
if name then
|
|
||||||
self:create()
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if name then
|
|
||||||
-- Ignore if it already exists
|
|
||||||
if self:cfgvalue(name) then
|
|
||||||
name = nil;
|
|
||||||
end
|
|
||||||
|
|
||||||
name = self:checkscope(name)
|
|
||||||
|
|
||||||
if not name then
|
|
||||||
self.err_invalid = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if name and #name > 0 then
|
|
||||||
self:create(name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Remove
|
-- Remove
|
||||||
crval = REMOVE_PREFIX .. self.config
|
local crval = REMOVE_PREFIX .. self.config
|
||||||
name = luci.http.formvaluetable(crval)
|
local name = luci.http.formvaluetable(crval)
|
||||||
for k,v in pairs(name) do
|
for k,v in pairs(name) do
|
||||||
if self:cfgvalue(k) and self:checkscope(k) then
|
if self:cfgvalue(k) and self:checkscope(k) then
|
||||||
self:remove(k)
|
self:remove(k)
|
||||||
|
@ -765,6 +739,34 @@ function TypedSection.parse(self)
|
||||||
end
|
end
|
||||||
AbstractSection.parse_optionals(self, k)
|
AbstractSection.parse_optionals(self, k)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.addremove then
|
||||||
|
-- Create
|
||||||
|
local crval = CREATE_PREFIX .. self.config .. "." .. self.sectiontype
|
||||||
|
local name = luci.http.formvalue(crval)
|
||||||
|
if self.anonymous then
|
||||||
|
if name then
|
||||||
|
self:create()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if name then
|
||||||
|
-- Ignore if it already exists
|
||||||
|
if self:cfgvalue(name) then
|
||||||
|
name = nil;
|
||||||
|
end
|
||||||
|
|
||||||
|
name = self:checkscope(name)
|
||||||
|
|
||||||
|
if not name then
|
||||||
|
self.err_invalid = true
|
||||||
|
end
|
||||||
|
|
||||||
|
if name and #name > 0 then
|
||||||
|
self:create(name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Verifies scope of sections
|
-- Verifies scope of sections
|
||||||
|
|
Loading…
Reference in a new issue