2.0.1 • Published 12 months ago

d98c_dynamic-forms v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

d98c_dynamic-forms

React Dynamic Form with Formik and Yup validations

NPM JavaScript Style Guide

Install

npm install --save d98c_dynamic-forms

Usage

import React, { Component } from 'react'

import DynamicForm from 'd98c_dynamic-forms'

class Example extends Component {
  render() {
    return (
      <DynamicForm
        formInputs={formInputs}
        onSubmit={(values) => console.log(values)}
      />
    )
  }
}

Input Required Object

You should provide an object array with the data for the input fields, following the next schema.

const formInputs = [
 {
    name: string,
    value: string | number | boolean,

    placeholder?: string,
    label?: string,
    inline?: 'true' | 'false',

    type: 'text' | 'radio-group' | 'email' | 'password' | 'select' | 'checkbox' | 'header',
    typeValue?: 'string' /* default */ | 'boolean' | 'number' | '',
    options?: [
      {
        value: string | number
        desc: string
      }
    ],
    //See validations section
    validations: [
      {
        type: 'required'
        value?: string
        message: string
      }
    ]
  }
]

Validations

List of supported validators by typeValue. In case that the typeValue attribute is not set, it'll be managed as a string.

If a wrong rule type is set, the whole rule would be ignored.

License

MIT © danny1998cuba

1.0.2

12 months ago

1.0.1

12 months ago

2.0.1

12 months ago

2.0.0

12 months ago

1.0.0

1 year ago

0.9.1

1 year ago

0.9.0

1 year ago