a-plus-forms-json-validator
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

A+ Forms JSON Schema Validator

This a plugin for the A+ forms that enables JSON schemas based forms validation.

Installation

npm install a-plus-forms
npm install a-plus-forms-json-validator

Usage

import { Form, ValidatorProvider, EmailInput, PasswordInput } from 'a-plus-forms';
import Validator from 'a-plus-forms-json-validator';

const schema = {
  type: 'object',
  properties: {
    email: { type: 'string', format: 'email' },
    password: { type: 'string' }
  },
  required: ['email', 'password']
};

const SignInForm = ({ onSubmit }) =>
  <ValidatorProvider validator={Validator}>
    <Form schema={schema} onSubmit={onSubmit}>
      <EmailInput name="username" label="Username" />
      <PasswordInput name="password" label="Password" />
    </Form>
  </ValidatorProvider>;

The ValidatorProvider doesn't have to be right next to the Form. The best practice is to place it next to your redux store provider or such, at the app root scope level.

All code in this repo is released under the terms of the MIT license. Copyright (C) 2017 Niklay Nemshilov

Package Sidebar

Install

npm i a-plus-forms-json-validator

Weekly Downloads

23

Version

1.0.6

License

MIT

Unpacked Size

8.74 kB

Total Files

6

Last publish

Collaborators

  • nikolay_nemshilov