form-metadata
Process serialized conditional logic for dynamic form field permissions and validation
Installation and Usage
Install via NPM:
npm install --save form-metadata
Import the module:
// ES2015 import// CommonJSconst processFields evaluateCondition prepareSubmission =
To run tests:
npm test
API
processFields(<fieldsJson>, <jsonPaths>)
Expects a jsonPaths
object mapping field key strings to JSON paths arrays.
Returns an object with two properties:
fields
- a flat tree with your fields' initial state, mirroring the structure of thejsonPaths
map you provided.fieldChangeEffects
- a tree of conditions organized by their dependencies.
evaluateCondition(<conditionalLogic>, <fields>, <jsonPaths>)
Evaluate a serialized condition. The second argument should have the same structure as those fields
returned by processFields
.
prepareSubmission(<jsonPaths>, <fieldsState>)
Takes a tree of fields data (structured like the fields
object returned from processFields()
) and transforms it back into the same structure as jsonPaths
. This way, you can send your JSON back to the server in the same format you received it..