https://github.com/edenreich/javascript-lazyform-module
A simple module to collect the data from the form. Built as a fluent pattern so its easy to use.
https://github.com/edenreich/javascript-lazyform-module
Last synced: 7 months ago
JSON representation
A simple module to collect the data from the form. Built as a fluent pattern so its easy to use.
- Host: GitHub
- URL: https://github.com/edenreich/javascript-lazyform-module
- Owner: edenreich
- Created: 2017-06-27T16:38:19.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-27T17:32:36.000Z (over 8 years ago)
- Last Synced: 2025-01-16T16:43:00.742Z (9 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Javascript-LazyForm-Module
A simple module to collect the data from the form. Built using a fluent pattern so its easy to use.## How to use
say we have following HTML.
```html
Demo
Select..
Option 1
Option 2
Option 3
```
Now we can use it like so:
```javascript
var form = document.getElementById('#form');
form.onsubmit = function(e) {
e.preventDefault();
var data = LazyForm.select(this)
.get(['inputs', 'selects', 'hidden'])
.toJson(); // or you can use toQueryString()
// next...send the data with ajax
}
```You also can use it outside of the event and pass the right selector like so(which is not so commonly used):
```javascript
LazyForm.select('#form')
.get(['inputs', 'selects', 'hidden'])
.toJson();
```## Options
- LazyForm.select() // accepts form object or a selector
- LazyForm.get(['inputs', 'selects', 'hidden', 'radioboxs', 'checkboxs']) // will query only the ones needed.
- LazyForm.toJson() // turns the data into a json object
- LazyForm.toQueryString() // turns the data into a key-value pairs## Notes
This still does not support multiple forms instances on a single request. You are welcome to send pull request to improve it.