libs/web: add "neg()" cbi datatype to negate arbritary types, e.g. "neg(hostname)" would allow "!example.com"

This commit is contained in:
Jo-Philipp Wich 2011-09-04 12:07:43 +00:00
parent 704824c956
commit 794094caa2
2 changed files with 16 additions and 0 deletions

View file

@ -218,6 +218,14 @@ var cbi_validators = {
if (!isNaN(max) && !isNaN(val))
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;
}
};

View file

@ -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