diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2010-10-12 23:08:54 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2010-10-12 23:08:54 +0000 |
commit | 17575b4d75cd9fede5ef0f3bfc7f9244fdb2ac06 (patch) | |
tree | f132423f036ce0cd3572de4b919c4e23d48e549a /libs/web | |
parent | eea83264264264929d6f198d7bd19446228acdf1 (diff) |
libs/web: rework cbi field validation, let validators return custom error messages, properly handle errors in multiple sections
Diffstat (limited to 'libs/web')
-rw-r--r-- | libs/web/luasrc/cbi.lua | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/libs/web/luasrc/cbi.lua b/libs/web/luasrc/cbi.lua index 8dd16b181e..993b422f66 100644 --- a/libs/web/luasrc/cbi.lua +++ b/libs/web/luasrc/cbi.lua @@ -1253,18 +1253,20 @@ function AbstractValue.parse(self, section, novld) end if fvalue and #fvalue > 0 then -- If we have a form value, write it to UCI - fvalue = self:transform(self:validate(fvalue, section)) + local val_err + fvalue, val_err = self:validate(fvalue, section) + fvalue = self:transform(fvalue) + if not fvalue and not novld then - if self.error then - self.error[section] = "invalid" - else - self.error = { [section] = "invalid" } - end - if self.section.error then - table.insert(self.section.error[section], "invalid") - else - self.section.error = {[section] = {"invalid"}} - end + val_err = val_err or "invalid" + + self.error = self.error or { } + self.error[section] = val_err + + self.section.error = self.section.error or { } + self.section.error[section] = self.section.error[section] or { } + table.insert(self.section.error[section], val_err) + self.map.save = false end if fvalue and not (fvalue == cvalue) then |