libs/web: add float and ufloat datatypes for field validation
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 5 Dec 2010 00:19:09 +0000 (00:19 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 5 Dec 2010 00:19:09 +0000 (00:19 +0000)
libs/web/htdocs/luci-static/resources/cbi.js
libs/web/luasrc/cbi/datatypes.lua

index 3959b69..992b558 100644 (file)
@@ -27,6 +27,16 @@ var cbi_validators = {
                return (cbi_validators.integer(v) && (v >= 0));
        },
 
+       'float': function(v)
+       {
+               return !isNaN(parseFloat(v));
+       },
+
+       'ufloat': function(v)
+       {
+               return (cbi_validators['float'](v) && (v >= 0));
+       },
+
        'ipaddr': function(v)
        {
                return cbi_validators.ip4addr(v) || cbi_validators.ip6addr(v);
index 2fdb580..62f06c4 100644 (file)
@@ -35,7 +35,7 @@ function bool(val)
        return false
 end
 
-function uint(val)
+function uinteger(val)
        local n = tonumber(val)
        if n ~= nil and math.floor(n) == n and n >= 0 then
                return true
@@ -44,7 +44,7 @@ function uint(val)
        return false
 end
 
-function int(val)
+function integer(val)
        local n = tonumber(val)
        if n ~= nil and math.floor(n) == n then
                return true
@@ -53,6 +53,11 @@ function int(val)
        return false
 end
 
+function ufloat(val)
+       local n = tonumber(val)
+       return ( n ~= nil and n >= 0 )
+end
+
 function float(val)
        return ( tonumber(val) ~= nil )
 end