-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support embedded/referenced object validation #12
Comments
Will this allow for referencing other nested properties in the form object? I'm currently trying to figure out how to compare two properties I have on an object that I have a schema for. var diffPercent = function(first, second){
return (second-first)/first * 100;
}
predicate.decreasedByMoreThanPercent = predicate.curry((val, params) => {
return predicate.num(val) &&
predicate.num(params.average) &&
predicate.num(params.target) &&
predicate.less(val, params.average) &&
predicate.greaterEq(Math.abs(diffPercent(val, params.average)), params.target);
});
var rules = [{
conditions: {
cost: {
decreasedByMoreThanPercent: {
average: "averages_monthly.cost",
target: 20
}
}
},
event: {
type: "whatever",
params: {
field: "something"
},
}
}];
var schema = {
definitions: {
averages_monthly: {
type: "object",
properties: {
cost: { type: "number" }
}
}
},
properties: {
cost: { type: 'number' },
averages_monthly: {
$ref: "#/definitions/averages_monthly"
}
}
};
var formData = {
cost: 50,
averages_monthly: {
cost: 100
}
} |
@CodestarGames As I understand you want to have a condition looking something like conditions: {
cost: {
decreasedByMoreThanPercent: {
average: "averages_monthly.cost",
target: 20
}
}
} This specific issue, is not for that. This is for validating references like "averages_monthly.cost", that averages_monthly actually has a cost field. This can be a good feature, I'll open a separate issue to address this. |
@CodestarGames I've fixed #14, so now it should work, by appending conditions: {
cost: {
decreasedByMoreThanPercent: {
average: "$averages_monthly.cost",
target: 20
}
}
} The fix is in the latest release 0.1.11 |
Currently this objects are ignored by the validator
The text was updated successfully, but these errors were encountered: