1.2.8 • Published 4 years ago

react-json-to-form v1.2.8

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

React Json To Form

Work with forms in React as jsons, control the fields and how your form render itself.

Demo

See this demo page and check it out.

Installation

npm

npm install react-json-to-form

yarn

yarn add react-json-to-form

usage

import React from 'react';
import Form from 'react-json-to-form';


class App extends React.Component {
  getFormData = () => {
    return {
      fields: [
        {
          name: "email",
          type: "email",
          label: {
            value: "Email"
          }
        },
        {
          name: "password",
          type: "password",
          label: {
            value: "Password"
          }
        },
        {
          name: "submit",
          type: "submit",
          value: "Login"
        }
      ]
    };
  };

  handleSubmit = (e, data) => {
    console.log(data);
  };

  render() {
    const formData = this.getFormData();

    return (
      <section>
        <Form
          data={formData}
          onSubmit={this.handleSubmit}
        />
      </section>
    );
  }
}

Props

PropTypeDefault ValueOptionsDescription
dataObject{}Data attributes specified belowJson data to transform to a form component
onSubmitfunction(e, formData) => {}Function to handle data when the form is submitted
childrenElement or element's arrayChildrens to render at the beginning of the form

Any other prop is passed directly as props to form DOM element Example: className, autoComplete, etc

Data props

PropTypeDefault ValueOptionsDescription
allFieldsRequiredboolfalsetrue falseSet all fields as required or not
fieldsGroupClassstringnullDefault Group of fields className
fieldClassstringnullDefault field className
labelClassstringnullDefault label className
inputClassstringnullDefault input className
fieldsarrayFields attributes specified belowList of fields to render in the form

Fields props

PropTypeDefault ValueOptionsDescription
typestringgroup text password email number date select textarea custom radio submit reset
namestring
valuestring
requiredbooltrue false
autoCompletestring
classNamestring
fieldClassstring
labelobjectLabel attributes specified below
optionsarrayOptions attributes specified below

Label props

PropTypeDefault ValueOptionsDescription
valuestring
classNamestring

Options props

PropTypeDefault ValueOptionsDescription
valuestring
labelstring
1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago