All Projects β†’ insin β†’ React Auto Form

insin / React Auto Form

Licence: mit
Simplifies getting user input from forms via onChange and onSubmit events, using DOM forms APIs

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Auto Form

React Router Form
<Form> is to <form> as <Link> is to <a>
Stars: ✭ 58 (-50%)
Mutual labels:  react-component, forms
insect
πŸ›  Highly customisable, minimalistic input x select field for React.
Stars: ✭ 33 (-71.55%)
Mutual labels:  forms, react-component
Tagify
πŸ”– lightweight, efficient Tags input component in Vanilla JS / React / Angular / Vue
Stars: ✭ 2,305 (+1887.07%)
Mutual labels:  react-component
React Flow Editor
React component which enables creating flow editors with ease
Stars: ✭ 110 (-5.17%)
Mutual labels:  react-component
Hooked Form
Performant 2KB React library to manage your forms
Stars: ✭ 110 (-5.17%)
Mutual labels:  forms
Jafar
🌟!(Just another form application renderer)
Stars: ✭ 107 (-7.76%)
Mutual labels:  forms
React Native Interactive Image Gallery
πŸ–Ό A React Native component to display a gallery of images.
Stars: ✭ 111 (-4.31%)
Mutual labels:  react-component
I7j Pdfhtml
pdfHTML is an iText 7 add-on for Java that allows you to easily convert HTML and CSS into standards compliant PDFs that are accessible, searchable and usable for indexing.
Stars: ✭ 104 (-10.34%)
Mutual labels:  forms
React Workshop
βš’ 🚧 This is a workshop for learning how to build React Applications
Stars: ✭ 114 (-1.72%)
Mutual labels:  forms
Quick Survey
A tool for quick surveys, try it out. (No longer maintained).
Stars: ✭ 109 (-6.03%)
Mutual labels:  forms
React Currency Input Field
React component for an input field
Stars: ✭ 111 (-4.31%)
Mutual labels:  react-component
React Stepper
Well-designed stepper component for react
Stars: ✭ 108 (-6.9%)
Mutual labels:  react-component
Pypdftk
Python module to drive the awesome pdftk binary.
Stars: ✭ 107 (-7.76%)
Mutual labels:  forms
Meteor Autoform
AutoForm is a Meteor package that adds UI components and helpers to easily create basic forms with automatic insert and update events, and automatic reactive validation.
Stars: ✭ 1,453 (+1152.59%)
Mutual labels:  forms
React Image Fallback
stop displaying broken images, have another image to fallback on.
Stars: ✭ 106 (-8.62%)
Mutual labels:  react-component
Clone Section Of Form Es6 Or Jquery
Now on npm. Using vanilla JavaScript (ES6) or jQuery to duplicate a section of a form, maintaining accessibility (a11y).
Stars: ✭ 112 (-3.45%)
Mutual labels:  forms
Dirty Check Forms
🐬Detect Unsaved Changes in Angular Forms
Stars: ✭ 105 (-9.48%)
Mutual labels:  forms
React Jsonschema Form
A React component for building Web forms from JSON Schema.
Stars: ✭ 10,870 (+9270.69%)
Mutual labels:  forms
React Multi Select
A Multi Select component built with and for React
Stars: ✭ 111 (-4.31%)
Mutual labels:  react-component
React Magnifier
πŸ” React image zoom component
Stars: ✭ 116 (+0%)
Mutual labels:  react-component

React <AutoForm>

Travis Codecov npm package

An <AutoForm> React component, which simplifies getting data from its contained form inputs via their onChange events and the form's onSubmit event, optionally trimming text input.

Live Demo

Install

npm install react-auto-form
import AutoForm from 'react-auto-form'
// or
var AutoForm = require('react-auto-form')

Browser bundles are available, which export a global AutoForm variable and expect to find a global React variable to work with.

Usage

The following React component skeleton shows usage of AutoForm to handle getting input onChange and onSubmit, plus the argument signatures it expects event callbacks to have:

class ExampleForm extends React.Component {
  _onChange = (event, name, data, change) => {
    // ...
  }

  _onSubmit = (event, data) => {
    // ...
  }

  render() {
    return <AutoForm onChange={this._onChange} onSubmit={this._onSubmit} trimOnSubmit>
      {/* ...form inputs... */}
    </AutoForm>
  }
}

API

AutoForm component

This component handles bubbling onChange events for convenient handling of input data changes as they happen and extraction of submittable form data.

It saves you from having to manually configure an onChange handler for each individual form input and from having to manually extract data from form inputs.

In order to do this, it expects form inputs contained within it to have name attributes set up as you would for any form which will be used for regular form submission.

Multiple inputs with the same name are supported - their extracted data will always be contained in an Array when they have some submittable data, with the exception of a group of radio buttons all having the same name, which will return the selected value only.

The data extracted from form inputs and the form as a whole is in line with data which would be submitted for the form's current state via a regular form submission - this makes it suitable for use in isomorphic apps which configure a form for regular submission and progressively enhance form-handling when JavaScript runs on the client.

Where available, data extracted from file inputs will be native File objects.

AutoForm props

You can pass all the usual form attributes to AutoForm (action, method, encType, noValidate etc.), and they will be passed on to the <form> it renders for you by default.

The following props are treated specially:

component

The component which will be rendered by AutoForm - defaults to 'form'.

onChange: Function(event, name, data, change)

If this prop is given, AutoForm will configure the form with an onChange handler which will handle onChange events from any inputs contained within the form, extract data for the form element which triggered the event and call the given onChange function with the following arguments:

  1. event:SyntheticEvent - the event being handled.

  2. name: string - the name of the form element which was the target of the event.

  3. data: null|boolean|string|string[]|File|File[] - submittable data for the form element which changed.

    This value will be as documented for the get-form-data module's getFieldData() return value.

    The TL;DR for that is:

    • data for an empty text input will be an empty String ('').
    • data for any other type of input which doesn't have a submittable value will be null.
    • data for a single checkbox input which is checked and doesn't have a value will be true.
    • data for an <input type="file"> will be a File if the browser supports the File API. If the input has a multiple attribute, data will be a list of Files when any are selected.
  4. change: Object.<string,null|boolean|string|string[]|File|File[]> - an object containing {[name]: data}, for convenience if you're using controlled form components and need to call setState() on every change.

onSubmit: Function(event, data)

If this prop is given, AutoForm will configure the form with an onSubmit handler which will handle the form's onSubmit event, extract submittable data for the form's elements and call the given onChange function with the following arguments:

  1. event:SyntheticEvent - the event being handled.

  2. data: Object.<string,null|boolean|string|string[]|File|File[]> - submittable data for the form.

    The properties of this object will be as documented for the get-form-data module's getFormData() return value.

trimOnSubmit: boolean (default: false)

If true, user input from text inputs will be trimmed of leading and trailing whitespace only when it is being extracted after an onSubmit event.

trim: boolean (default: false)

If true, user input from text inputs will always be trimmed of leading and trailing whitespace when it is being extracted.

When true, this prop takes precedence over trimOnSubmit.

Note: It's not advisable to use the trim prop in conjunction with onChange and controlled input components, as the user will be completely disallowed from entering a leading or trailing space, so they won't be able to enter information containing spaces without copying and pasting it. Just use trimOnSubmit instead in this case.

MIT Licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].