js-data / js-data-schema

Define and validate rules, datatypes and schemata in Node and in the browser.
http://www.js-data.io/docs/js-data-schema
MIT License
18 stars 10 forks source link

more params to be passed to validators #6

Closed nlac closed 9 years ago

nlac commented 9 years ago

Hi, what is the preferred way to define/use validator rules with more parameters like eg. "between"?

If i define a rule "between" and try this one

DS.defineResource({
    schema: {
        age {
            between: {min:20,max:30}
        }
    }
});

exception will be thrown Uncaught Error: Rule configuration for rule "between" cannot be an object!

This one

            between: [20,30]

is accepted, i can refer the params in the rule like param[0], param[1]

Is there another way? I didn't see example for this case. I no other way, the array solution is fine, just wondering.

jmdobry commented 9 years ago

I believe it can't be an object because the recursion has to be able to know when to stop going deeper. There is no way for it to know whether an object is just a deeper part of your nested data, or the list of rules for the current attribute its traversing.