1.3.1 • Published 1 year ago

populate.js v1.3.1

Weekly downloads
13
License
MIT
Repository
-
Last release
1 year ago

populate.js

A simple JavaScript populate( form, data ) function which will populate form fields from a JSON object.

Input types (text, email, select, multiple select, etc) are taken into account but not validated.

Usage

HTML

<form id="my-form">
	<input type="text" name="name" />
	<input type="email" name="email" />

	<input type="text" name="address[addr1]" />
	<input type="text" name="address[city]" />
	<input type="text" name="address[state]" />
</form>

JavaScript

// your JSON object
// keys have to match input names
var data = {
	"email": "john@doe.com",
	"name": "John Doe",
	"address": {
		"addr1": "Street name",
		"city": "City name",
		"state": "State"
	}
}

// your containing element
var formElement = document.getElementById('my-form');

// populate the form with our JSON object
populate(formElement, data);

Install

Load the JavaScript file in your browser directly or install using NPM:

npm install populate.js

License

MIT licensed.

1.3.1

1 year ago

1.3.0

1 year ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.3

7 years ago

1.0.2

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago