Skip to content

Commit 68a4438

Browse files
committed
fix #14
1 parent 0b25980 commit 68a4438

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ as such it has similar interface and configuration, but simplified predicate lan
1414
- Basic boolean operations (`and` `or` and `not`) that allow to have any arbitrary complexity
1515
- Rules expressed in simple, easy to read JSON
1616
- Declarative conditional logic with [predicates](https://github.com/landau/predicate)
17+
- Relevant conditional logic support
1718
- Support of nested structures with [selectn](https://github.com/wilmoore/selectn.js)
1819
including composite arrays
1920
- Secure - no use of eval()
@@ -481,6 +482,35 @@ let engine = new Engine([{
481482

482483
Validation will automatically catch new extension and work as expected.
483484

485+
## Relevant conditional logic
486+
487+
Sometimes you would want to validate `formData` fields one against the other.
488+
You can do this simply by appending `$` to the beginning of reference.
489+
490+
For example, you want to trigger event only when `a` is less then `b`, when you don't know ahead `a` or `b` values
491+
492+
```js
493+
let schema = {
494+
type: "object",
495+
properties: {
496+
a: { type: "number" },
497+
b: { type: "number" }
498+
}
499+
}
500+
501+
let rules = [{
502+
conditions: {
503+
a: { less: "$b" }
504+
},
505+
event: "some"
506+
}]
507+
508+
let engine = new Engine(schema, rules);
509+
```
510+
This is how you do it, in run time `$b` will be replaces with field `b` value.
511+
512+
Relevant fields work on nested objects as well as on any field condition.
513+
484514
## Events
485515

486516
Framework does not put any restrictions on event object, that will be triggered, in case conditions are meet

0 commit comments

Comments
 (0)