2.0.1 • Published 7 years ago

form-metadata v2.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

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>)

Example

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 the jsonPaths map you provided.
  • fieldChangeEffects - a tree of conditions organized by their dependencies.

evaluateCondition(<conditionalLogic>, <fields>, <jsonPaths>)

Example

Evaluate a serialized condition. The second argument should have the same structure as those fields returned by processFields.

prepareSubmission(<jsonPaths>, <fieldsState>)

Example

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.

2.0.1

7 years ago

2.0.0

7 years ago

1.4.0

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago