form-data-object

1.0.0 • Public • Published

Form Data Object badge-size npm version

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

  1. Import the plugin

        import allFormData from 'form-data-object';
  2. 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);
  3. Call method to return the single FormData object. E.g.

        myFormData.getFormData()

Parameters

(wrappers, encode, jsObject)

parameter description
wrapper(s) Type: array
Default: null

Array of DOM wrappers. If using a single wrapper, just place it in an array. More info in the Usage section
encode Type: boolean
Default: true

Do you want the data to use Javascript's encodeURIComponent()
jsObject Type: boolean
Default: false

Do you want to return a generic Javascript object instead of a FormData() object?

MIT © Chris Boakes

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    0
  • 0.0.2
    0
  • 0.0.1
    0

Package Sidebar

Install

npm i form-data-object

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • chrisboakes