npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-form-for-object

v2.0.1

Published

Simple ReactJS form builder for Javascript objects

Downloads

4

Readme

React Form For Object

No-effort, simple ReactJS form builder for Javascript objects.

Simply pass FormFor a javascript object and it will display the form and handle data for you. You can always override defaults by passing FormFor options.

There is a full working example here

Install

npm install react-form-for-object

OR

bower install react-form-for-object

Usage

FormFor will determine the type of input based on the your object. We do our best to detect the type of the input you're looking for. However, some things are harder to detect such as textarea. We give you the option to override them in the options by passing a type (see example below).

Supply a submit handler with onSubmit key in the options. On submit, FormFor will pass all of the form data to the callback you provided.

Supply a cancel handler with onCancel key in the options. If you don't want a cancel button, simply don't supply an onCancel handler.

FormFor will display all errors supplied to it in the errors prop.

If we can't successfully detect the type of value from an object attribute, we default to text input.

By default, id attributes are built as hidden input.

import FormFor from 'react-form-for-object';

const todo = {
  name: "Clean my room",
  description: "My room needs some serious cleaning",
  completed: false,
  list: "Home",
};

const inputOptions = {
  labels: true, // by default we use placeholders, but you can turn on labels and we will use both.
  description: { type: 'textarea' },
  list: { type: 'select', values: [{value:"Home", show: "Home"}, {value:"Work", show: "Work"}] },
};

<FormFor
  object={todo}
  inputOptions={inputOptions}
  onSubmit={ (data) => console.log(data) }
  onCancel={ (data) => console.log(data) }
/>

How to use the options

Each attribute on your object can have its own options/overrides. In your option object, use the name of the attribute as the key (see example above). Currently you can supply the following options:

  • type: 'textarea', 'select' (please see supported inputs below). Please keep in mind that you don't have to supply any options for FormFor to work, only supply them to override what we give you based on your object attributes.
  • className
  • value
  • labels: turned off by default.
  • placeholder: we use the name of the field, you can override that (this also affects label, if labels are turned on).

Labels

You can pass a labels: true attribute in the form options. We will then use the input placeholder (if you specified it in the options) or input name as the label.

Input support

  • text
  • checkbox
  • number
  • hidden
  • select
  • password
  • textarea
  • date
  • datetime
  • email
  • submit
  • color

Examples

A working example can be found here

TODO

  • file
  • image
  • month
  • radio
  • range
  • reset
  • search
  • tel
  • url
  • week