js-data-schema icon indicating copy to clipboard operation
js-data-schema copied to clipboard

Add rule to schema?

Open leandroz opened this issue 10 years ago • 4 comments

I have a schema that has 3 fields, "a", "b" and "c". At least one of them has to be not null. Is there a way to add a rule to the schema instead of to a field?, I could create a rule and apply it to each of the 3 but I think that a rule to the schema itself could be better.

leandroz avatar May 25 '15 06:05 leandroz

Your rules are executed in the context of the object under test, so in a custom rule you can access other fields for validation that involves multiple fields simultaneously.

jmdobry avatar May 25 '15 06:05 jmdobry

Sure, but the idea is that the rule is for the schema instead of for a field, in this caseI have to add the rule to each field and the concept is that the error is not for a particular field, but for the schema itself. I know that I can make it work how you said, but the concept is different.

leandroz avatar May 25 '15 06:05 leandroz

You could add the rule to just one of the fields, since you need the rule to run once, not three times.

jmdobry avatar May 25 '15 14:05 jmdobry

Yes you are right, but having a feature that lets you add a rule to the schema I think that could be better for this case.

leandroz avatar May 26 '15 01:05 leandroz