From: Jo-Philipp Wich Date: Tue, 27 Apr 2010 00:27:37 +0000 (+0000) Subject: libs/cbi: X-Git-Tag: 0.10.0~684 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=eca5a0abf07d6c4a08278bec9c578bdf294929c8;p=oweals%2Fluci.git libs/cbi: - skip client side field validation if corrsponding field was removed due to dependencies - human readable error strings in uci section summary - implement field validation for dnyamic lists - render optional fields when section has tabs --- diff --git a/libs/cbi/htdocs/luci-static/resources/cbi.js b/libs/cbi/htdocs/luci-static/resources/cbi.js index 7cdca642d..4af6e58d9 100644 --- a/libs/cbi/htdocs/luci-static/resources/cbi.js +++ b/libs/cbi/htdocs/luci-static/resources/cbi.js @@ -488,15 +488,19 @@ function cbi_validate_field(cbid, optional, type) { var validator = function(reset) { - field.className = field.className.replace(/ cbi-input-invalid/g, ''); - - // validate value - var value = (field.options) ? field.options[field.options.selectedIndex].value : field.value; - if( !(((value.length == 0) && optional) || vldcb(value)) ) + // is not detached + if( field.form ) { - // invalid - field.className += ' cbi-input-invalid'; - return false; + field.className = field.className.replace(/ cbi-input-invalid/g, ''); + + // validate value + var value = (field.options) ? field.options[field.options.selectedIndex].value : field.value; + if( !(((value.length == 0) && optional) || vldcb(value)) ) + { + // invalid + field.className += ' cbi-input-invalid'; + return false; + } } return true; diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua index a18d37d60..cc22229fc 100644 --- a/libs/cbi/luasrc/cbi.lua +++ b/libs/cbi/luasrc/cbi.lua @@ -813,7 +813,7 @@ function AbstractSection.parse_optionals(self, section) local field = self.map:formvalue("cbi.opt."..self.config.."."..section) for k,v in ipairs(self.children) do - if v.optional and not v:cfgvalue(section) then + if v.optional and not v:cfgvalue(section) and not next(self.tabs) then if field == v.option then field = nil self.map.proceed = true @@ -1290,7 +1290,7 @@ end -- Render if this value exists or if it is mandatory function AbstractValue.render(self, s, scope) - if not self.optional or self:cfgvalue(s) or self:formcreated(s) then + if not self.optional or next(self.section.tabs) or self:cfgvalue(s) or self:formcreated(s) then scope = scope or {} scope.section = s scope.cbid = self:cbid(s) @@ -1339,12 +1339,20 @@ end -- Validate the form value function AbstractValue.validate(self, value) if self.datatype and value and datatypes[self.datatype] then - if datatypes[self.datatype](value) then - return value + if type(value) == "table" then + local v + for _, v in ipairs(value) do + if v and #v > 0 and not datatypes[self.datatype](v) then + return nil + end + end + else + if not datatypes[self.datatype](value) then + return nil + end end - else - return value end + return value end AbstractValue.transform = AbstractValue.validate diff --git a/libs/cbi/luasrc/view/cbi/dynlist.htm b/libs/cbi/luasrc/view/cbi/dynlist.htm index 8e2bda8f9..826e2e698 100644 --- a/libs/cbi/luasrc/view/cbi/dynlist.htm +++ b/libs/cbi/luasrc/view/cbi/dynlist.htm @@ -1,7 +1,7 @@ <%# LuCI - Lua Configuration Interface Copyright 2008 Steven Barth -Copyright 2008 Jo-Philipp Wich +Copyright 2008-2010 Jo-Philipp Wich Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -42,4 +42,11 @@ $Id$ <% end -%> <% if i <= #vals then %>
<% end end %> +<% if self.datatype then -%> + +<% end -%> <%+cbi/valuefooter%> diff --git a/libs/cbi/luasrc/view/cbi/ucisection.htm b/libs/cbi/luasrc/view/cbi/ucisection.htm index b184908b0..db32c9043 100644 --- a/libs/cbi/luasrc/view/cbi/ucisection.htm +++ b/libs/cbi/luasrc/view/cbi/ucisection.htm @@ -31,7 +31,17 @@ $Id$ <% if self.error and self.error[section] then -%>
-
    <% for _, e in ipairs(self.error[section]) do %>
  • <%=pcdata(e):gsub("\n","
    ")%>
  • <% end %>
+
    <% for _, e in ipairs(self.error[section]) do -%> +
  • + <%- if e == "invalid" then -%> + <%:One or more fields contain invalid values!%> + <%- elseif e == "missing" then -%> + <%:One or more required fields have no value!%> + <%- else -%> + <%=pcdata(e)%> + <%- end -%> +
  • + <%- end %>
<%- end %>