|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
DisclaimerThe author does not accept responsibility for any effects, adverse or otherwise, that this code may have on you, your computer, your sanity, your dog, and anything else that you can think of. Use it at your own risk. (Deja Vu? I also love the Allegro disclaimer). Quick and Dirty TourSo you don't like to read long articles or you don't have time for it, then just download the source files, run the demo HTML files on your preferred browser. BackgroundAlthough the inner works require you to be an advanced Web developer to understand and improve it, you need only to have basic knowledge of HTML and JavaScript to use the Framework. IntroductionBuilding cross-browser masks and validating data aren't simple tasks. And there isn't a definitive solution for this topic, but we can, with some assumptions, come up with a feasible solution. Before getting into the code, let's revisit some keywords:
Basics (or Talking is Cheap...)Let's start with the page that will have some data entry fields ready to be filled. The validationDemo.htm page will look like the image below: ...
<fieldset>
<legend>Search block</legend>
F1 number(3)<input ai_name="myNumber" type="text" ai_block="search">
<br />
F2 number(3,2) <input id="number3point2" type="text" ai_block="search" />
...
As you can see, no JavaScript is present on the page (except for the configuration call at the bottom of the page), and no information about how the fields should behave either. In the demo, we have two distinct blocks that should be validated separately. The next thing to do is to create an uncoupled way of configuring our pages. For complex systems, we could build an XML file for every page that needs validation, but for our small demo, let's build a single XML file (validationDemo.xml). ...
<validation>
<field name="myNumber" block="search|insert" personality="number"
precision="3,0" required="true" />
<field id="number3point2" block="search" personality="number" precision="3,2" />
<field id="date" block="search" personality="date" />
...
The XML is almost self-explanatory, as it only specifies each field behavior. For instance, the Smart MasksSmart masks, as I conceive, should come in pairs: one real-time filter mask and a post-validation companion function. Our little Framework has some mask ready to use and to serve as an example. ...
case 'time' : //15:00
mask = "TimeMask";
...
if( mask != null )
if( pageValidator.Masks[mask] != null )
oSrcElement.onkeypress = pageValidator.Masks[mask];
...
Since it is an advanced feature, let’s keep walking for the last act of our show, the validation of the input. Validation (or Trust, but Check)By now, we have only one more step to go: validation of the inputs. This step is performed when the user clicks on the Validate button and it triggers the validation of the block specified as a parameter, as in your test page: <input type="submit" value="Validate Search" id="Submit2"
onclick="return pageValidator.IsValidForm('frmPage', 'search');" />
You must pass the form to be validated. The section if omitted will be all by default, where the entire form would be validated. Since each page object has its intelligence within, the The "]>" Characters vs. XHTML ValidationA few comments about the If page validation is no concern for you yet, you may safely remove the custom block from the HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
ConclusionAnd that’s it for the simple-but-effective abstraction layer! As you could see, it’s very simple to use, so it can be applied easily on small or mid sized Web systems. Its inner works may not be simple or easy to understand at first because of the complex divergences of major browsers. All the code presented is free of copyrights and may be used freely as long as you maintain the references to its authors. ReferencesThe best resources you could find:
History
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||