2.0.1 • Published 8 years ago
form-metadata v2.0.1
form-metadata
Process serialized conditional logic for dynamic form field permissions and validation
Installation and Usage
Install via NPM:
npm install --save form-metadataImport the module:
// ES2015 import
import { processFields, evaluateCondition, prepareSubmission } from 'form-metadata'
// CommonJS
const { processFields, evaluateCondition, prepareSubmission } = require('form-metadata')To run tests:
npm testAPI
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 thejsonPathsmap 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.