form-data-object
v1.0.0
Published
Creates a single FormData object (or generic javascript object - optional) from multiple wrapper elements and encodes the data (optional) with no framework dependencies.
Downloads
14
Maintainers
Readme
Form Data Object
Creates a single FormData object (or generic javascript object - optional) from multiple wrapper elements and encodes the data (optional) with no framework dependencies.
- Fast and lightweight
- Doesn't rely on a form tag (you can use whichever wrapper tag you like)
- You can use multiple wrappers
- Optionally encodes the data
- No framework dependencies
Installation
However you like:
<script src="dist/form-data-object.min.js"></script>
npm install --save form-data-object
Usage
Import the plugin
import allFormData from 'form-data-object';
Instantiate the class and pass it your wrapper elements in an array. E.g.
let myFormData = new allFormData([document.getElementById('my-form'), document.getElementById('my-other-div')]);
or, if you just want a single wrapper
let myFormData = new allFormData([document.getElementById('my-form')]);
maybe you don't want the data to be encoded
let myFormData = new allFormData([document.getElementById('my-form')], false);
maybe you want the data returned as a generic javascript object (instead of FormData)
let myFormData = new allFormData([document.getElementById('my-form')], true, true);
Call method to return the single FormData object. E.g.
myFormData.getFormData()
Parameters
(wrappers, encode, jsObject)
MIT © Chris Boakes