@rajduandc/ruleengine
Version:
Rule engine for kantime
172 lines (151 loc) • 4.24 kB
Markdown
A library for custom validation in the form based on user defined json schema. It is not limited to validation but can perform different actions based on business rules.
| Features | Description |
| ------ | ------ |
|On Demand Validation | Validate form on button click |
| Event Driven Validation | Validate item on different events of input elements such as focus out, onChange,etc |
| Skip Logic | Based on rules it skip certain sections of form |
| State Management | To show, hide, disable, enable and making read only certain sections of forms based on rules. |
using npm :
```sh
$ npm i -g npm
$ npm i --save kantime-rule-engine
```
Initialize:
```sh
import {SkipRuleEngine, EventDrivenRuleEngine,FormStateRuleEngine,OnDemandRuleEngineExecution, EventBinding,SetInputData} from 'kantime-rule-engine';
```
```sh
ComponentDidMount() {
SkipRuleEngine();
EventDrivenRuleEngine();
FormStateRuleEngine();
EventBinding();
}
render() {
let EngineInputdata={};
EngineInputdata= {...};
SetInputData(EngineInputdata,this.props.masterRules,this.props.formRules);
// It is used to verify the data and check return values for defined rule
}
```
___
```json
"Rule1" : {
"Eval" : [
"EQ",
"doc.student.name",
""
],
"actionData" : {
"print" : {
"message" : "Name can't be blank",
"tgtEleInfo" : [
"Student.Name",
"Name",
"Name"
]
}
}
}
```
___
```json
"Rule1" : {
"Eval" : [
"NOTBETWEEN",
"doc.student.age",
"0,14"
],
"actionData" : {
"Mandate" : {
"message" : [
"Age must be between 0 to 14 ",
"warning"
],
"event" : "focusout",
"srcEleInfo" : [
"Student.Age",
"stu_age"
]
}
}
},
```
___
```json
"Rule1" : {
"Eval" : [
"EQ",
"doc.student.physicalDisorder",
"No"
],
"actionData" : {
"Skip" : {
"srcEleInfo" : [
"Student.PhysicalDisorder",
"stu_disorder"
],
"tgtEleInfo" : [
"Student.Identification",
"stu_ident"
],
"skipEleInfo" : [
"stu_disorderType",
"stu_certificateNo"
]
}
}
}
```
___
```json
"Rule1" : {
"Eval" : [
"EQ",
"doc.student.status",
"Qualified"
],
"actionData" : {
"Hide" : [
"btn_delete",
"btn_lock"
],
"Show" : [
"btn_email",
"btn_addToList",
"btn_Save"
]
}
},
```
| Operators |
| ------ |
|LENGTH|
|REGEX_MATCH|
|REGEX_NOT_MATCH|
|EQ|
|NEQ|
|GT|
|GTEQ|
|LT|
|LTEQ|
|OR|
|AND|
|IN|
|NOTIN|
|CONTAIN|
|NOTCONTAIN|
|SUBSTRING|
|NOTBETWEEN|
|DATEDIFF|
|HASDUPLICATE|