validate-json-schema-form

1.0.2 • Public • Published

validate-json-schema-form

NPM version build status Test coverage Downloads js-standard-style

Validate a form using JSON Schema.

Installation

$ npm install validate-json-schema-form

Usage

<form id="signup-form">
  <input name="username" type="text" placeholder="username"></input>
  <input name="password" type="password" placeholder="password"></input>
</form>
const validator = require('validate-json-schema-form')
 
const validate = validator({
  required: [ 'username' ],
  type: 'object',
  properties: {
    username: { type: 'string' },
    password: { type: 'string' }
  }
})
 
const form = document.querySelector('#signup-form')
validate(form, (err, data) => {
  if (err) console.error(err)
  console.log(data)
})

API

validate = validator(schema)

Create a form validator out of a JSON Schema.

validate(el, [opts], cb(err, data))

Validate a form element and call a callback with the results. Opts can contain the following values:

  • [tbi] partial=false - set to true to only validate non-empty values.
  • [tbi] formats - define custom formats.
  • [tbi] schemas - reference external schemas.

See Also

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    2
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i validate-json-schema-form

Weekly Downloads

2

Version

1.0.2

License

MIT

Last publish

Collaborators

  • yoshuawuyts