Git Product home page Git Product logo

form's Introduction

#Yet another Form utility for React.js

Example

Wrap your component via decorator withForm, then you can place your fields inside using Field component

import { withForm, Field } from 'form';

function MyApp({handleSubmit}) {
  return <form onSubmit={handleSubmit}>
    <Field name="name" component="input" />
    <Field name="email" type="email" component="input" />
  </form>
}

withForm({
  onSubmit(data) {
    // do something with submitted and valid data
    console.log(data);
  }
})(MyApp);

For more comprehensive example, see example folder.

API

withForm([formOptions])(Component)

Turns your component into form. Available options:

  • onSubmit(data) - function, that called when submit is triggered and validation has passed
  • initialValues - initial values for the form

Those options also can be provided as props during render. E.g.:

const MyAppForm = withForm()(MyApp)

ReactDOM.render(<MyAppForm onSubmit={submitCallback} />)

Field

React component that renders field.

  • component - required A react component, that will be used to render field. Can be also a string, input or select, for example.
  • name - required Name of the field
  • validation(value, name, formValues) - a validation function that should return undefined to mark field as passed. If function returns a value, it will be used as an error message

form's People

Contributors

just-boris avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.