1.0.1 • Published 7 years ago

react-form-getter v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

React-Form-Getter

Get the values from your React form with one, simple utility function.

Installation

This package is distributed via npm:

npm install react-form-getter

Usage

Add a ref to the form element and pass it as an argument to the rfGetter function. This will return all nested inputs in a results object <name, inputValue>. Each input should have a name attribute in order to be added to the results object.

const rfGetter = require('react-form-getter');

class Login extends Component {

	handleSubmit() {
	  const formData = rfGetter(this.form);
	  /*
	   formData:
	     {
		   textInput: 'textValue',
		   passwordInput: 'passwordValue'
	     }		
	  */
	}

	render() {
	  return (
		<form 
		  ref={(form) => { this.form = form; }} 
		  onSubmit={this.handleSubmit}>
		 <input
            type="text"
            name="textInput"
            value="textValue"
          />
          <input
            type="password"
            name="passwordInput"
            value="passwordValue"
          />
          <input type="sumbit" />
		</form>
	  );
	}
}

Other

This utility was developed by Lee Mordell

Project Setup

Clone the repo, install the dependencies, then run the tests.

  • $ git clone https://github.com/lmordell/React-Form-Getter.git
  • $ cd React-Form-Getter
  • $ npm install
  • $ npm test