@maryojo/react-flexform

1.0.0 • Public • Published

@maryojo/react-flexform

Auto generate React form using JSON schema

NPM JavaScript Style Guide

Install

npm install --save @maryojo/react-flexform

Usage

import React from 'react'

import { FormGenerator } from '@maryojo/react-flexform'
import 'react-flexform/dist/index.css'

import formSchema from './schema/form.json'

const customValidations = {
  customPhoneValidation: (val) => {
    if (val?.length < 11) {
      return 'Invalid email address'
    }
    return null
  },
  customEmailValidation: (val) => {
    if (!val?.includes('@')) {
      return 'Invalid email address'
    }
    return null
  }
}

const App = () => {
  return (
    <>
      <div style={{ width: '50%' }}>
        <FormGenerator
          schema={formSchema}
          customValidations={customValidations}
        />
      </div>
    </>
  )
}

export default App

License

MIT © maryojo

Readme

Keywords

none

Package Sidebar

Install

npm i @maryojo/react-flexform

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

35.7 kB

Total Files

7

Last publish

Collaborators

  • maryojo