form-serialize-all
v1.0.1
Published
Simple form serialization without jquery
Downloads
95
Readme
Index
Installation
yarn
yarn add form-serialize-all
npm
npm install --save form-serialize-all
Usage
<form action="" class="example-form">
<input type="text" value="My awesome name" name="name" />
<input type="text" value="My awesome surname" name="surname" />
<input type="checkbox" value="I am the most modest person in the world" name="modest" checked="" />
</form>
import SerializeForm from 'form-serialize-all';
const myFormElement = document.querySelector('.example-form');
const seralize = new SerializeForm(myFormElement);
console.log(seralize.toArray()); // [{name:'My awesome name'}, {surname:'My awesome surname'}, {modest:'I am the most modest person in the world'}]
console.log(seralize.toObject()); //{name:'My awesome name', surname:'My awesome surname', modest:'I am the most modest person in the world'}
console.log(seralize.toString()); // 'name=My awesome name&surname=My awesome surname&modest=I am the most modest person in the world'