From 3cbb9b379670a46c0d52ed5b55f4129367ce1516 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 16 Dec 2011 05:53:11 +0000 Subject: [PATCH] luci-0.10: merge r8102 --- libs/web/htdocs/luci-static/resources/cbi.js | 18 ++++++++++++++++++ libs/web/luasrc/cbi/datatypes.lua | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/libs/web/htdocs/luci-static/resources/cbi.js b/libs/web/htdocs/luci-static/resources/cbi.js index d1e34d178..8d32b669d 100644 --- a/libs/web/htdocs/luci-static/resources/cbi.js +++ b/libs/web/htdocs/luci-static/resources/cbi.js @@ -233,6 +233,24 @@ var cbi_validators = { if (args[0] && typeof cbi_validators[args[0]] == "function") return cbi_validators[args[0]](v.replace(/^\s*!\s*/, '')); + return false; + }, + + 'list': function(v, args) + { + var cb = cbi_validators[args[0] || 'string']; + if (typeof cb == "function") + { + var cbargs = args.slice(1); + var values = v.match(/[^\s]+/g); + + for (var i = 0; i < values.length; i++) + if (!cb(values[i], cbargs)) + return false; + + return true; + } + return false; } }; diff --git a/libs/web/luasrc/cbi/datatypes.lua b/libs/web/luasrc/cbi/datatypes.lua index 93b29cba8..9a3b73500 100644 --- a/libs/web/luasrc/cbi/datatypes.lua +++ b/libs/web/luasrc/cbi/datatypes.lua @@ -282,3 +282,17 @@ function neg(val, what) return false end + +function list(val, what, ...) + if type(val) == "string" and what and type(_M[what]) == "function" then + for val in val:gmatch("%S+") do + if not _M[what](val, ...) then + return false + end + end + + return true + end + + return false +end -- 2.25.1