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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-form-fields

v0.1.9

Published

Form fields packaged into a react class, supports validation, url parameter autofill, relationships and HTML5 polyfill for placeholders

Readme

React Form Fields

Form fields packaged into a react class, supports validation, url parameter autofill, relationships and HTML5 polyfill for placeholders

npm install react-form-fields

For HTML5 placeholder polyfill versioning is defined in the DOM using conditional comments, to support <IE9 include these in your html:

<!--[if lt IE 7 ]> <html class="ie ie6"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie ie7"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie ie8"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html><!--<![endif]-->

Usage

Text input

var FormFields = require('react-form-fields');
ReactDOM.render(
	<FormFields
		tag="input" 
		validation="alphanumeric" 
		errorMsg="This field is required and only accepts alpha numeric characters" 
		required={true} 
		attributes={{
			type: 'text',
			placeholder: 'Alpha numeric text input',
			name: 'my-input',
			id: 'my-input'
		}}
	/>,
	document.getElementById('react-form-field')
);

Checkbox input

var FormFields = require('react-form-fields');
ReactDOM.render(
	<FormFields
		tag="input" 
		errorMsg="This field is required" 
		required={true} 
		attributes={{
			type: 'checkbox',
			name: 'my-input',
			id: 'my-input',
			value: 'agreed to terms'
		}}
	/>,
	document.getElementById('react-form-field')
);

Radios

var FormFields = require('react-form-fields');
ReactDOM.render(
	<FormFields
		tag="input" 
		attributes={{
			type: 'radio',
			name: 'my-input',
			id: 'my-input'
		}} 
		options={[
			{
				value: 'option-1',
				label: 'Option 1'
			},
			{
				value: 'option-2',
				label: 'Option 2'
			}
		]} 
		legend="My Radios"
	/>,
	document.getElementById('react-form-field')
);

Select

var FormFields = require('react-form-fields');
ReactDOM.render(
	<FormFields
		tag="select" 
		attributes={{
			placeholder: 'Please select an option',
			name: 'my-input',
			id: 'my-input'
		}} 
		options={[
			{
				value: 'option-1',
				label: 'Option 1'
			},
			{
				value: 'option-2',
				label: 'Option 2'
			}
		]} 
	/>,
	document.getElementById('react-form-field')
);

Textarea

var FormFields = require('react-form-fields');
ReactDOM.render(
	<FormFields
		tag="textarea" 
		attributes={{
			placeholder: 'Alpha numeric text input',
			name: 'my-input',
			id: 'my-input'
		}}
	/>,
	document.getElementById('react-form-field')
);

Form validation example

var FormFields = require('react-form-fields');
var Form = React.createClass({

	// .....

	validate: function(e){
		e.preventDefault();
		var self = this,
			valid = true,
			inputs = Object.keys(this.refs).filter(function(key) {
				return key.indexOf('react-form-field-') == 0;
			}).reduce(function(data, key) {
				data[key] = self.refs[key];
				return data;
			}, {});
		for(var key in inputs) {
			if(!inputs[key].validate()) {
				valid = false;
			}
		}
		if(!valid) {
			e.preventDefault();
		} else {
			// its valid
		}
	},

	render: function(){
		return (
			<form onSubmit={this.validate}>
				<FormFields
					ref="react-form-field-1" 
					tag="input" 
					validation="email" 
					errorMsg="Please enter a valid email address" 
					required={true} 
					attributes={{
						type: 'text',
						placeholder: 'Your email',
						name: 'email',
						id: 'email'
					}}
				/>
				<button type="submit">Submit</button>
			</form>
		);
	}

});

ReactDOM.render(
	<Form />,
	document.getElementById('react-form-field')
);

Options

tag

Type: string

Default: input

Options: input, select, textarea

Determines the type of form field, if using input specify the attribute type as text, radio or checkbox

errorMsg

Type: string

Default: This field is invalid

The error message that is appended after the input if it is required and empty or if validation fails

required

Type: boolean

Default: false

If this field is required, will fail validation if empty

validation

Type: regexp | string

Options: regexp object, regexp string, email, numeric, alpha, alphanumeric

Field validation, accepts regexp or a predefined option

options

Type: array

Example:

	options={[
		{
			value: 'option-1',
			label: 'option 1'
		},
		{
			value: 'option-2',
			label: 'option 2'
		}
	]}

An array of options for use with radio or select field tags

parameter

Type: string

Auto populate field based on a url parameter, example 'email' would auto populate field if url contains the email parameter http://localhost:4000/[email protected]

relationship

Type: string

Accepts another form elements id and will fail validation if the input value does not match, used for confirmational email/phone number fields

onChange

Type: function

A callback function for change events, callback contains event object

onBlur

Type: function

A callback function for blur events, callback contains event object

onFocus

Type: function

A callback function for focus events, callback contains event object

onValidate

Type: function

A callback function to be fired when field is validated, callback contains valid boolean

legend

Type: string

For use with radio fields, if specified will add a fieldset legend

attributes

Type: object

Assigns attributes directly to the form field

attributes.type

Type: string

Default: text

The type of input, to be used with the field tag of input to define a text or checkbox input

attributes.placeholder

Type: string

The placeholder

attributes.name

Type: string

Default: react-form-field

The field name

attributes.id

Type: string

Default: react-form-field

The field id

attributes.className

Type: string

Class assigned to the field

attributes.autoComplete

Type: string

Options: off

Will disable default browser auto complete on load, clears field

attributes.value

Type: string

Prepopulate field value, will fire change events and validate if prop changes

License

MIT © Simon Staton