Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

react-form-controlled-validate

1.0.6 • Public • Published

React controlled form validate

Validation of the forms. High order components for react-form-controlled. It is based on JSON Schema.

NPM version build status Test coverage

Simple arrays

If you are using fieldset with simple array do not enter the name attribute.

import React, { Component } from 'react';
import Form from 'react-form-controlled';
import Validate, { Alert } from 'react-form-controlled-validate';
 
const schema = {
  type: 'object',
  required: ['firstName'],
  firstName: {
    username: {
      type: 'string',
      minLength: 2,
    },
  },
};
 
export default class Example extends Component {
  constructor(props, context) {
    super(props, context);
 
    this.state = {};
  }
 
  onSubmit = (data) => {
    alert(`Hi ${data.firstName}`);
  }
 
  render() {
    return (
      <Validate schema={schema}>
        <Form
          value={this.state}
          onSubmit={this.onSubmit}
        >
          <input name="firstName" />
          <Alert name="firstName" />
 
          <button type="submit">Submit</button>
      </Form>
    );
  }
}

Support us

Star this project on GitHub.

Try our other React components

License

The MIT License (MIT)

Copyright (c) 2016 Zlatko Fedor

Install

npm i react-form-controlled-validate

DownloadsWeekly Downloads

35

Version

1.0.6

License

MIT

Unpacked Size

87.7 kB

Total Files

37

Last publish

Collaborators

  • avatar