loading...
Cover image for A simple way to work with Forms in React

A simple way to work with Forms in React

ngduc profile image Duc Ng ・1 min read

A simple way to work with Forms in React. This is my attempt to address complicate form rendering:

import { FormContainer, Form, Field, Button } from 'ez-react-form';

<FormContainer onSubmit={this.onSubmit} render={props => (
  <Form use="bootstrap4">
    <Field label="Text" name="text" />
    <Field name="password" />
    <Field textarea name="textarea" />
    <Field select options={animals} name="select" />
    <Field radios options={genders} name="radio" />
    <Field checkboxes options={roles} name="checkboxes" />
    <Field number name="number" />
    <Field date name="date" />
    <Field time name="time" />
    <Field toggle inline name="toggle" />
    <Field file label="File Upload" name="file1" />
    <Field file withPreview label="File Upload (with Preview)" name="file2" />
    <Field range name="range" />

    <Button type="submit"/>
    <Button>Cancel</Button>
  </Form>
)} />

Result: (Full form, validation (with yup) & error messages)

Example

Demo
Github

I appreciate any feedbacks, suggestions or ideas below. Thanks! :)

Posted on Nov 2 '18 by:

ngduc profile

Duc Ng

@ngduc

JS enthusiast / 15y tinkering with screens & code.

Discussion

markdown guide