+ CREATORS OF NEW MEDIA CAMPAIGNS
Blog
- Home »
- Blog
jQuery FormLabels Plugin
Published by Andrei Zharau on June 16, 2010 &bull 15 Comments
Overview
The idea of using captions on form input boxes is not new, but all previous methods of providing this functionality have a few disadvantages. The jQuery FormLabels Plugin is a result of working with hundreds of different clients, sites, and especially forms. Every form is different, so building a uniform label generator was not an easy task. The plugin has a few advantages over other plugins and "tricks" with similar functionality:
- Form label has
almostthe same styling as its "parent" input element - Labels on password input boxes look like text, not asterisks
- Accurate label's positioning regardless of size and other properties of input box
- Simplicity: no need to change a form's markup or CSS in order to get the labels work
- Multiple options and methods including safemode option for legacy browsers
- Animation
- Cross-Browser support
Usage
This plugin is intended to work with the following elements:
- input[type='text']
- input[type='email']
- input[type='password']
- textarea
To generate a label for an input element add a title attribute into the HTML tag:
<input type="email" name="email" title="Email Address" />
<input type="password" name="password" title="Password" />
<input type="text" name="password" title="Secret Word" />
<textarea name="comments" title="Comments...">
You should include plugin initialization as well:
<script>
$(function(){
$.fn.formLabels();
});
</script>
See the demo page for more usage details.
Options
| Key | Default | Description |
|---|---|---|
| excludeElts | none | Elements to be excluded from global labels creation on a page [demo] |
| refreshOnResize | false | Whether or not refresh labels on window 'resize' event. Useful if you use 'body' as a parent container for your labels [demo] |
| safemode | false | Enable legacy safe mode without any DOM modifications (very limited functionality; see the plugin's code for details) [demo] |
| labelParent | 'body' | Specifies a block that will store the form labels. Can be either 'body' or 'form' - the closest form element of targeted input [to see the differences between this two modes, firebug demos of two first options] |
Method
| Method | Example | Description |
|---|---|---|
| refreshLabels() | $.fn.formLabels.refreshLabels() | This method refreshes label's position relatively to its corresponding creator - input element. Useful when you made changes in your form and want to re-position labels because positions of inputs have been changed. [demo] |
Dependencies
The plugin requires jQuery 1.4 and jQueryUI 1.8
Changelog
1.0RC2
- the plugin supports a new refresh method
- new options: safemode and labelParent
- slightly updated performance
1.0RC1
- Basic functionality
No Comments
+ DESIGN FROM BOSTON
LIBERTY CONCEPTS
119 BRAINTREE ST
BOSTON, MA 02134
SUITE 602
(P) 1.617.987.0103
(F) 1.617.987.0829
INFO@LIBERTYCONCEPTS.COM
LIBERTY CONCEPTS
119 BRAINTREE ST
BOSTON, MA 02134
SUITE 602
(P) 1.617.987.0103
(F) 1.617.987.0829
INFO@LIBERTYCONCEPTS.COM


