From: Jo-Philipp Wich Date: Sun, 4 Sep 2011 12:07:43 +0000 (+0000) Subject: libs/web: add "neg()" cbi datatype to negate arbritary types, e.g. "neg(hostname... X-Git-Tag: 0.11.0~1797 X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=commitdiff_plain;h=794094caa20d922d968b4615f44a189f25f48a5e libs/web: add "neg()" cbi datatype to negate arbritary types, e.g. "neg(hostname)" would allow "!example.com" --- diff --git a/libs/web/htdocs/luci-static/resources/cbi.js b/libs/web/htdocs/luci-static/resources/cbi.js index 1cd49bc65..1e751d47e 100644 --- a/libs/web/htdocs/luci-static/resources/cbi.js +++ b/libs/web/htdocs/luci-static/resources/cbi.js @@ -219,6 +219,14 @@ var cbi_validators = { return (val <= max); return false; + }, + + 'neg': function(v, args) + { + if (args[0] && typeof cbi_validators[args[0]] == "function") + return cbi_validators[args[0]](v.replace(/^\s*!\s*/, '')); + + return false; } }; diff --git a/libs/web/luasrc/cbi/datatypes.lua b/libs/web/luasrc/cbi/datatypes.lua index 6640db639..fc3048e37 100644 --- a/libs/web/luasrc/cbi/datatypes.lua +++ b/libs/web/luasrc/cbi/datatypes.lua @@ -267,3 +267,11 @@ function max(val, max) return false end + +function neg(val, what) + if what and type(_M[what]) == "function" then + return _M[what](val:gsub("^%s*!%s*", "")) + end + + return false +end