Kim Johnson schrieb:
Quick question: is it possible to bunch rules together
in Jorn's validator, similar to how you can bunch
cases in a switch statement?
Ex:
rules: { storyscore: {required: true},
story: {required: true},
animationscore: {required: true},
animation: {required: true},
}
Is it possible to change to something like:
rules: { storyscore, story, animationscore, animation:
{required: true} }
My jquery code is large and bloated so I've been
trying to figure out ways to cut corners (and didn't
see any examples on the demo page that did this) --
insight would be appreciated! :)
JavaScript is great for code generation. Something like this (untested)
should do the trick:
function dumpRules(ids, rules) {
var result = {};
$.each(ids.split(","), function(key, value) {
result[value] = rules;
}
return result;
}
rules: dumpRules("storyscore,story,animationscore,animation", {required: true});
Not yet any shorter, but that'd pay off with a few more options.
Worth adding to the plugin?
--
Jörn Zaefferer
http://bassistance.de