form-metadata-2
v2.0.0
Published
Process serialized conditional logic for dynamic form field permissions and validation
Downloads
185
Keywords
Readme
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
import { processFields, evaluateCondition, prepareSubmission } from 'form-metadata'
// CommonJS
const { processFields, evaluateCondition, prepareSubmission } = require('form-metadata')
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..