An open API service indexing awesome lists of open source software.

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.

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.