Validate a virtual-form using JSON Schema.
$ npm install virtual-form-validation
const validator = require('virtual-form-validation')
const validate = validator({
type: 'object',
additionalProperties: false,
required: [ 'name' ],
properties: {
name: { type: 'string' },
address: { type: 'string' }
}
})
module.exports = render
function render (h, state) {
return h('form', { validate: validate }, [
h('input', { type: 'text', name: 'name', placeholder: 'name' }),
h('input', { type: 'text', name: 'address', placeholder: 'address' }),
h('input', { type: 'submit', name: 'SUBMIT' })
]))
}
Create a validator based on a JSON schema.
validate
should be attached to a virtual-dom
form node as a property. It
uses hooks under the hood to perform actions whenever the internal state of the
form mutates. It performs the following behavior:
- sets the
:required
/:optional
pseudo-classes - sets the
:valid
/:invalid
pseudo-classes on validation