Calendar
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| << < | > >> | |||||
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||
Archives
- October 2006 (3)
- September 2006 (10)
- August 2006 (10)
- July 2006 (53)
- June 2006 (1)
- November 2005 (2)
- More...
Monthly Statistics
Search
Syndicate this blog
Forms with moo.fx part 1 meta info
As you can tell by the title, I intend this to be a multi-part series on using moo.fx to create better forms. In the first installment we are going to create a form that displays a hint to the user about the type of information that is expected in an input box. What does it look like? Why does this require its own article? Well it probably doesn't but I want these pieces to be modular and if I were to lump too many functions in one article it would be different to separate one piece from another. I don't like how-to articles that tell you how to build a house when you really want to install a sink so let's keep each article on a more basic level. Why would you need this?
The Code function getLabelText(id) {
<form action="/custom/cma" method="post" name="cma_form" id="cma_form" class="cma_form"> Sample CSS .TEditBox {
How It Works To make the form degrade in browsers that don't support JavaScript or don't have it enabled, we place HTML labels next to the input boxes. Since we don't intend to see these labels, we set the font size to 0 and set the width to a very small value and make them invisible. A more complete version would swap the CSS using JavaScript to set these values rather than CSS so it would degrade normally but that will be included in part 2 of this series.Now that the labels exist and are invisible, we call the initialization function from the body load event. This code locates all the TEditBox class inputs and hooks up the blur and focus events so the input areas can change their appearance automatically. The nice part about this code is that it will not throw an error if no input boxes are present and it also doesn't need to be rewritten for each new form because it finds the controls that it will change automatically. So back to part one, the labels were present to help when degrade with the browser but they also exist so the system knows what text to put into the inputs when the control loses focus. It does this by walking the labels and finding the one that has the 'for' set to the 'id' of the input that we are connected to. The last part is the class switching that happens when the controls lose focus and regain focus. To make them stand apart, we have three state. Focused with data, unfocused with data and unfocused without data. This concludes part one of the series. Part two will refine the degradation and begin introducing Ajax'd validation using moo.ajax. Stay tuned... Related PostsForms with moo.fx part 2Yet Another Ajax Contact Page Ajax Tabs Reloaded: based on the Havoc Studios article Simple Ajax Code-Kit (fixed) What happened to... |
