├── LICENSE
├── README.md
├── package.js
├── parse-form-min.js
├── parse-form.js
└── smart.json
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Adam Brodzinski
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Parse-Form
2 |
3 | Parse form is a micro library used to parse a form's input fields and return it's values. It also provide some helper methods to grab the raw nodes and jQuery wrapped nodes.
4 |
5 |
6 |
7 | ### Install
8 |
9 | In Meteor apps use `meteor add skinnygeek1010:parse-form` to install the Meteor package.
10 | Otherwise, add the `parse-form-min.js` file to your project with a script tag.
11 |
12 |
13 |
14 |
15 | ### Useage
16 |
17 | Assuming that this piece of HTML is in the DOM, let's get started.
18 |
19 | ```html
20 |
27 | ```
28 |
29 |
30 |
31 |
32 | We call `new ParseForm` and pass in the form element. Alternatively you can also pass in a jQuery selector like `#new-user-form`. To access the input values, use the input name as a key. e.g. `form.name == 'John Doe'`
33 |
34 |
35 | ```javascript
36 | // form = new ParseForm(e.target);
37 | var form = new ParseForm('#new-user-form');
38 |
39 | form.name == 'John Doe'
40 | form.email == 'john@gmail.com'
41 | form.password == 'password1'
42 | ```
43 |
44 |
45 |
46 |
47 | ### Manipulate
48 |
49 | If you would like to further manipulate the form and it's input elements, jQuery wrapped elements are attached to the form object with a `$` prefix. e.g., `$name`
50 |
51 | ```js
52 | var form = new ParseForm('#new-user-form');
53 |
54 | // access the jQuery wrapped input
55 | form.$username.val('foo');
56 |
57 | // `form.$el` - grab the form wrapped in jQuery
58 | form.$el.find('.thing');
59 |
60 | // grab the form's raw DOM node
61 | form.el
62 |
63 | // clears contents of form
64 | form.reset();
65 | ```
66 |
--------------------------------------------------------------------------------
/package.js:
--------------------------------------------------------------------------------
1 | Package.describe({
2 | summary: "A light utility to parse and manipulate forms"
3 | });
4 |
5 | Package.on_use(function (api) {
6 |
7 | // make sure jQuery is loaded on client
8 | api.use(["jquery"], "client");
9 |
10 | // load parse form lib onto client
11 | api.add_files("parse-form.js", ["client"]);
12 |
13 | // export global contructor
14 | api.export('ParseForm', 'client');
15 | });
16 |
17 |
--------------------------------------------------------------------------------
/parse-form-min.js:
--------------------------------------------------------------------------------
1 | // Parse Form - https://github.com/AdamBrodzinski/parse-form
2 | ParseForm=function(e){var t=this;if(!e)return console.error("You must provide an element or selector");this.$el=$(e);this.el=this.$el[0];this.inputs=this.$el.serializeArray();for(var n=0;n>> 'jdoe@gmail.com'
23 | this[name] = $el.val();
24 | // save jquery selector, e.g. form.$email
25 | this['$' + name] = $el;
26 | }
27 |
28 | };
29 |
30 | // reset/empty the form
31 | ParseForm.prototype.reset = function () {
32 | this.el.reset();
33 | };
--------------------------------------------------------------------------------
/smart.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "parse-form",
3 | "description": "A micro library used to parse and manipulate forms",
4 | "homepage": "https://github.com/AdamBrodzinski/parse-form",
5 | "author": "Adam Brodzinski",
6 | "version": "0.2.1",
7 | "git": "https://github.com/AdamBrodzinski/parse-form.git"
8 | }
9 |
10 |
--------------------------------------------------------------------------------