A couple of weeks ago, I posted an article [1] about the formReForm Project [2]. formReForm is a methodology to style HTML forms without a huge amount of markup (or [gasp] a Table-based layout). Taking it one step further, this article discusses how to use the formReForm javascript library to create usable, accessible and beautiful user input interfaces.
[Note: It was brought to my attention that the project name "reform" was already being used. So "reform" has been renamed to "formReForm" ... which is actually what it does. -- joe]
To see formReForm in action, take a look at the demo [3]. What you'll see first is a non-styled form with default sized input elements. Click the "reForm this form GUI" button to see formReForm in action.
formReForm styles your forms.All form elements (input, select, textarea, etc) are fixed-size by default. So we are handed a nasty bill-of-goods with each new web project:
The original posting generated several positive comments on other sites (such as CSS-Tricks.com [4], usabilita.blongosfere.it [5], and a google group posting [6]). There's been some concerns, and hopefully this post will answer those questions.
Last time we looked at how the DIVs and the CSS interact. This posting provides some basic screenshots and examples of how the Javascript modifies HTML DOM to create the intended effect.
Using formReForm requires just a few lines of javascript in your HTML:
// you have the option of dynamically loading the formReForm.css file:
formReForm.loadformReFormCss();
// create the formReForm object and pass
// it the name of the form's DIV container:
formReForm = new FormReForm('fieldForm');
// apply the reForm to your GUi,
formReForm.doReForm();
// done!
Next, create a basic HTML form:
<div class="fieldForm" id="fieldForm">
<label for="givenName">First Name</label>
<input name="givenName" id="givenName" value="Joe" type="text"/><br/>
<label for="sirName">Last Name</label>
<input name="sirName" id="sirName" value="Lippeatt" type="text"/><br/>
<label for="phone">Phone</label>
<!-- deleted for brevity -->
</div> <input id="phone" name="phone" value="905 555 1212" type="text"/><br/>
which would typically result in a minimally formatted gui such as this:
[7]Minimally Styled Form GUI: The reForm "Before" image
Although its not real pretty, this form is completely accessible and usable. This is how a formReForm form block would look if Javascript was disabled.
formReForm works its magic after the page has been loaded by calling the javascript formReForm.doReform() method. This can be called by any event handling technique such as the body onload event. The demo file uses a click event for dramatic effect.
formReForm.doReform() manipulates DOM so that code that looks like this:
<label for="givenName">First Name</label>
<input name="givenName" id="givenName" value="Joe" type="text"/><br/>
is "reFormed" to look like this:
<div class="field50Pct">
<div class="fieldItemLabel">
<label for="givenName">First Name</label>
</div>
<div class="fieldItemValue">
<input id="givenName" type="text" value="Joe" name="givenName"/>
</div>
</div>
Although this appears to have an excessive number of div tags, consider that this is much more desirable than a table-based layout. The original markup is functional and semantic; formReForm.js and formReForm.css does all the heavy lifting.
All of these screen shots are from the same form markup. The only thing that has changed is the width of the browser window:
At 800px, formReForm creates a nice 4-column layout with re-sized text boxes. There are some form fields that are twice as long as others, for example, the "Address" field.
At 540px, textboxes and textareas automatically shrink to fit. Still plenty of room.
At 450px, textboxes drop below titles, but remain indented so the form is still usable.
At 290px, the form turns into a single column, the text boxes are indented and the form still looks great.
Notice that the form checkboxes also accommodates whatever space is available after formReForming.
formReForm is available on Google code [16] where you can download the latest versions and demos. You can also submit bug reports and suggest updates. Hopefully, formReForm can provide you enough flexibility to create great, usable, well-designed user input forms.
Links:
[1] http://css.dzone.com/news/scriptless-self-adjusting-form
[2] http://code.google.com/p/formreform/
[3] http://houstonupa.org/reForm/demo.html
[4] http://css-tricks.com/links-of-interest-20/
[5] http://groups.google.com/group/net-gold/browse_thread/thread/4fb88d214393f490
[6] http://groups.google.com/group/net-gold/browse_thread/thread/4fb88d214393f490
[7] http://css.dzone.com/sites/all/files/images/FormNoStyleSmall.gif
[8] http://css.dzone.com/sites/all/files/images/Form800.preview.gif
[9] http://css.dzone.com/sites/all/files/images/Form540.preview.gif
[10] http://css.dzone.com/sites/all/files/images/Form448.preview.gif
[11] http://css.dzone.com/sites/all/files/images/Form293.preview.gif
[12] http://css.dzone.com/sites/all/files/images/CheckboxesUnstyled757pxl.preview.gif
[13] http://css.dzone.com/sites/all/files/images/Checkboxes753.preview.gif
[14] http://css.dzone.com/sites/all/files/images/Checkboxes544.preview.gif
[15] http://css.dzone.com/sites/all/files/images/Checkboxes292.preview.gif
[16] http://code.google.com/p/formreform/
You are viewing a mobilized version of this site...
View original page here