skinnygeek1010:parse-form

v0.2.1Published 10 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Parse-Form

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.

Install

In Meteor apps use meteor add skinnygeek1010:parse-form to install the Meteor package.
Otherwise, add the parse-form-min.js file to your project with a script tag.

Useage

Assuming that this piece of HTML is in the DOM, let's get started.

1<form id='new-user-form'>
2    <input type="text"     name="email">
3    <input type="text"     name="username">
4    <input type="password" name="password">
5    
6    <input type="submit" value="Create User">
7</form>

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'

1//  form = new ParseForm(e.target);
2var form = new ParseForm('#new-user-form');
3
4form.name      ==  'John Doe'
5form.email     ==  'john@gmail.com'
6form.password  ==  'password1'

Manipulate

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

1var form = new ParseForm('#new-user-form');
2
3// access the jQuery wrapped input
4form.$username.val('foo');
5
6// `form.$el` - grab the form wrapped in jQuery
7form.$el.find('.thing');
8
9// grab the form's raw DOM node
10form.el
11
12// clears contents of form
13form.reset();