Changeset 6446
- Timestamp:
- 11/16/10 19:48:02 (3 years ago)
- Location:
- luci/trunk/libs/web
- Files:
-
- 3 modified
-
htdocs/luci-static/resources/cbi.js (modified) (3 diffs)
-
luasrc/cbi.lua (modified) (1 diff)
-
luasrc/cbi/datatypes.lua (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
luci/trunk/libs/web/htdocs/luci-static/resources/cbi.js
r6369 r6446 156 156 { 157 157 return (v.match(/^[a-zA-Z0-9_]+$/) != null); 158 }, 159 160 'range': function(v, args) 161 { 162 var min = parseInt(args[0]); 163 var max = parseInt(args[1]); 164 var val = parseInt(v); 165 166 if (!isNaN(min) && !isNaN(max) && !isNaN(val)) 167 return ((val >= min) && (val <= max)); 168 169 return false; 158 170 } 159 171 }; … … 635 647 { 636 648 var field = (typeof cbid == "string") ? document.getElementById(cbid) : cbid; 649 var vargs; 650 651 if( type.match(/^(\w+)\(([^\(\)]+)\)/) ) 652 { 653 type = RegExp.$1; 654 vargs = RegExp.$2.split(/\s*,\s*/); 655 } 656 637 657 var vldcb = cbi_validators[type]; 638 658 … … 650 670 ? field.options[field.options.selectedIndex].value : field.value; 651 671 652 if( !(((value.length == 0) && optional) || vldcb(value )) )672 if( !(((value.length == 0) && optional) || vldcb(value, vargs)) ) 653 673 { 654 674 // invalid -
luci/trunk/libs/web/luasrc/cbi.lua
r6355 r6446 1359 1359 -- Validate the form value 1360 1360 function AbstractValue.validate(self, value) 1361 if self.datatype and value and datatypes[self.datatype] then 1362 if type(value) == "table" then 1363 local v 1364 for _, v in ipairs(value) do 1365 if v and #v > 0 and not datatypes[self.datatype](v) then 1361 if self.datatype and value then 1362 local args = { } 1363 local dt, ar = self.datatype:match("^(%w+)%(([^%(%)]+)%)") 1364 1365 if dt and ar then 1366 local a 1367 for a in ar:gmatch("[^%s,]+") do 1368 args[#args+1] = a 1369 end 1370 else 1371 dt = self.datatype 1372 end 1373 1374 if dt and datatypes[dt] then 1375 if type(value) == "table" then 1376 local v 1377 for _, v in ipairs(value) do 1378 if v and #v > 0 and not datatypes[dt](v, unpack(args)) then 1379 return nil 1380 end 1381 end 1382 else 1383 if not datatypes[dt](value, unpack(args)) then 1366 1384 return nil 1367 1385 end 1368 1386 end 1369 else 1370 if not datatypes[self.datatype](value) then 1371 return nil 1372 end 1373 end 1374 end 1387 end 1388 end 1389 1375 1390 return value 1376 1391 end -
luci/trunk/libs/web/luasrc/cbi/datatypes.lua
r6370 r6446 209 209 return (val:match("^[a-zA-Z0-9_]+$") ~= nil) 210 210 end 211 212 function range(val, min, max) 213 val = tonumber(val) 214 min = tonumber(min) 215 max = tonumber(max) 216 217 if val ~= nil and min ~= nil and max ~= nil then 218 return ((val >= min) and (val <= max)) 219 end 220 221 return false 222 end
