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
This commit is contained in:
parent
c4ac5b8eb8
commit
eca5a0abf0
4 changed files with 45 additions and 16 deletions
|
@ -487,6 +487,9 @@ function cbi_validate_field(cbid, optional, type)
|
||||||
if( field && vldcb )
|
if( field && vldcb )
|
||||||
{
|
{
|
||||||
var validator = function(reset)
|
var validator = function(reset)
|
||||||
|
{
|
||||||
|
// is not detached
|
||||||
|
if( field.form )
|
||||||
{
|
{
|
||||||
field.className = field.className.replace(/ cbi-input-invalid/g, '');
|
field.className = field.className.replace(/ cbi-input-invalid/g, '');
|
||||||
|
|
||||||
|
@ -498,6 +501,7 @@ function cbi_validate_field(cbid, optional, type)
|
||||||
field.className += ' cbi-input-invalid';
|
field.className += ' cbi-input-invalid';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -813,7 +813,7 @@ function AbstractSection.parse_optionals(self, section)
|
||||||
|
|
||||||
local field = self.map:formvalue("cbi.opt."..self.config.."."..section)
|
local field = self.map:formvalue("cbi.opt."..self.config.."."..section)
|
||||||
for k,v in ipairs(self.children) do
|
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
|
if field == v.option then
|
||||||
field = nil
|
field = nil
|
||||||
self.map.proceed = true
|
self.map.proceed = true
|
||||||
|
@ -1290,7 +1290,7 @@ end
|
||||||
|
|
||||||
-- Render if this value exists or if it is mandatory
|
-- Render if this value exists or if it is mandatory
|
||||||
function AbstractValue.render(self, s, scope)
|
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 = scope or {}
|
||||||
scope.section = s
|
scope.section = s
|
||||||
scope.cbid = self:cbid(s)
|
scope.cbid = self:cbid(s)
|
||||||
|
@ -1339,13 +1339,21 @@ end
|
||||||
-- Validate the form value
|
-- Validate the form value
|
||||||
function AbstractValue.validate(self, value)
|
function AbstractValue.validate(self, value)
|
||||||
if self.datatype and value and datatypes[self.datatype] then
|
if self.datatype and value and datatypes[self.datatype] then
|
||||||
if datatypes[self.datatype](value) then
|
if type(value) == "table" then
|
||||||
return value
|
local v
|
||||||
|
for _, v in ipairs(value) do
|
||||||
|
if v and #v > 0 and not datatypes[self.datatype](v) then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return value
|
if not datatypes[self.datatype](value) then
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
AbstractValue.transform = AbstractValue.validate
|
AbstractValue.transform = AbstractValue.validate
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<%#
|
<%#
|
||||||
LuCI - Lua Configuration Interface
|
LuCI - Lua Configuration Interface
|
||||||
Copyright 2008 Steven Barth <steven@midlink.org>
|
Copyright 2008 Steven Barth <steven@midlink.org>
|
||||||
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
|
Copyright 2008-2010 Jo-Philipp Wich <xm@subsignal.org>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -42,4 +42,11 @@ $Id$
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% if i <= #vals then %><br />
|
<% if i <= #vals then %><br />
|
||||||
<% end end %>
|
<% end end %>
|
||||||
|
<% if self.datatype then -%>
|
||||||
|
<script type="text/javascript">
|
||||||
|
<% for i=1, #vals + 1 do -%>
|
||||||
|
cbi_validate_field('<%=cbid%>.<%=i%>', <%=tostring(self.optional == true or i > #vals)%>, '<%=self.datatype%>');
|
||||||
|
<%- end %>
|
||||||
|
</script>
|
||||||
|
<% end -%>
|
||||||
<%+cbi/valuefooter%>
|
<%+cbi/valuefooter%>
|
||||||
|
|
|
@ -31,7 +31,17 @@ $Id$
|
||||||
|
|
||||||
<% if self.error and self.error[section] then -%>
|
<% if self.error and self.error[section] then -%>
|
||||||
<div class="cbi-section-error">
|
<div class="cbi-section-error">
|
||||||
<ul><% for _, e in ipairs(self.error[section]) do %><li><%=pcdata(e):gsub("\n","<br />")%></li><% end %></ul>
|
<ul><% for _, e in ipairs(self.error[section]) do -%>
|
||||||
|
<li>
|
||||||
|
<%- 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 -%>
|
||||||
|
</li>
|
||||||
|
<%- end %></ul>
|
||||||
</div>
|
</div>
|
||||||
<%- end %>
|
<%- end %>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue