Uni-Form XHTML Forms Custom Tags v2
Posted on June 2, 2008 at 12:39 AM in ColdFusion, Uni-Form Tag Library, jQuery
It's been almost six months now since I released v1 of the library, so I figured it was high time I make time to add some enhancements. Here's a quick overview of the new features:
- Integrated dependencies
- Integrated support for the following jQuery plugins
- Date Picker
- Time Entry
- Input Masking
- Validation
- Path Configuration
Let's look at some of the new goodies in more detail...
Integrated Dependencies
After a few months of using the library myself, one of the things that started to annoy me was the fact that I had to add the following into all of my applications in order to use the library:
- <link href="/cfMgmt/common/UniForm/css/uni-form.css" type="text/css" rel="stylesheet" media="all" />
- <link href="/cfMgmt/common/UniForm/css/uni-form-styles.css" type="text/css" rel="stylesheet" media="all" />
- <!--[if lte ie 6]>
- <style type="text/css" media="screen">.uniForm,.uniForm fieldset,.uniForm .ctrlHolder,.uniForm .formHint{ /* Trigger hasLayout*/zoom:1;}</style>
- <![endif]-->
- <InvalidTag src="/cfMgmt/common/UniForm/js/uni-form.jquery.js" type="text/javascript"></script>
I originally "fixed" this by using a <cfinclude />. While this worked okay, it was still kinda annoying to me, as I did not want to include the requirements on every page load. With this release, you no longer have to worry about that nonsense, because the dependencies are loaded automagically when you call the library.
Integrated jQuery plugins: Date Picker
v2 has a brand new 'loadDateUI' argument on the form tag, which accepts a boolean. If your form needs a date picker in it, just provide this new argument and set it to true.
- <uform:form action="action.cfm"
- id="myForm"
- loadDateUI="true">
Integrated jQuery plugins: Time Entry
Need a time entry field? Just use the new 'loadTimeUI' argument...
- <uform:form action="action.cfm"
- id="myForm"
- loadTimeUI="true">
Integrated jQuery plugins: Input Masking
"What about input masking?" you ask. You guessed it; just supply the 'loadMaskUI' argument...
- <uform:form action="action.cfm"
- id="myForm"
- loadMaskUI="true">
Integrated jQuery plugins: Validation
What good is a form without validation, right? Not much, to be sure. v2 utilizes jQuery's form validation plugin, which is integrated by setting the 'loadValidation' argument to true...
- <uform:form action="action.cfm"
- id="myForm"
- loadValidation="true">
... along with the new 'validation' argument for the field tag.
- <uform:field label="First Name"
- name="contactFirstName"
- isRequired="true"
- type="text"
- validation="required" />
One of the really bad-ass things about this plugin is that you can do basic client-side validation by simply adding a class to the field, such as 'required'. The plugin will check to make sure that field was filled out, and displays an error message if it isn't. Just supply validation="required" as shown above, and you're done. No JavaScript to write. Nothing. Just add it to your CF and stick a fork in it.
For those of you who like to take advantage of the more advanced features of the validation plugin, you should be able to continue to do so by utilizing this same argument. However, I must admit that I have not done any advanced testing with it as of yet, so if you run into any difficulties with that, please feel free to contact me and hopefully we can work together to iron it out.
Path Configuration
To load all of the various dependencies, the library uses convention to locate the required files. Should your application's directory structure require you to use paths other than the defaults (same directory structure as the download), you can utilize the form tag's new 'config' argument to supply the correct paths.
- <uform:form action="action.cfm"
- id="myForm"
- config="#myConfigStruct#">
As you can see, the config argument accepts a structure. Valid keys are:
- renderer: path to the error message renderer
- uniformCSS: path to the uni-form.css file
- uniformJS: path to the jquery.uni-form.js file
- validationJS: path to the jquery.validate.js file
- dateCSS: path to the ui.datepicker.css file
- dateJS: path to the ui.datepicker.js file
- timeCSS: path to the jquery.timeentry.css file
- timeJS: path to the jquery.timeentry.js file
- maskJS: path to the jquery.maskedinput.js file
IMPORTANT NOTE #1!
Some of the JavaScript files have had modifications made to them in order to integrate with the Uni-Form markup. Changing the files will break things, so I would recommend changing only the path to them!
IMPORTANT NOTE #2!
For page load speed, the packed versions of the various JavaScript files are used. If you get really, really bored and decide to dig into them to see what changes I made, good luck. ;-)
IMPORTANT NOTE #3!
ALL of the new 'load{Dependency}' arguments default to FALSE. If you're not using a particular plugin for your form, no need to supply the argument. The scripts/CSS will *not* be loaded.
IMPORTANT NOTE #4!
It is assumed that you use jQuery for more than just your forms, and therefore already have it loaded by default. If, however, you don't, I decided at the last minute to include an argument to load it automatically with the form...
- <uform:form action="action.cfm"
- id="myForm"
- loadjQuery="true">
If you're not using jQuery elsewhere in your application, what the hell is wrong with you??!!??!!
:-)
Oh yeah, and if you decide to alter the path to jQuery itself, you can supply the 'jQuery' key in the config struct.
Summing it Up
Wanna see it in action?
Thanks to Dan Wilson for his contributions, and to everyone else out there that has had kind words for the library. You guys (and gals) all make it fun to release code. :-)
Update
Please see the 2.1 release for the download.
Latest Articles
- No recent entries.
Categories
- ColdBox (21) [RSS]
- ColdFusion (92) [RSS]
- Fusebox (3) [RSS]
- General (22) [RSS]
- jQuery (15) [RSS]
- Kalendar (1) [RSS]
- Linux (1) [RSS]
- Mura CMS (1) [RSS]
- Railo (1) [RSS]
- Rants (5) [RSS]
- Transfer (8) [RSS]
- Uni-Form Tag Library (36) [RSS]
Quick Links
Blogs I Read
Calendar
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
« Mar | ||||||
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 |
Subscribe
Enter a valid email address.
On 6/2/08 at 6:34 AM, Tom K said:
One of the first things I did was put the JS on cfhtmlhead on the form tag :)
i'm still trying to work out how to make a dropdown filled from a query though :(
On 6/2/08 at 7:32 AM, Sebastiaan said:
On 6/2/08 at 2:02 PM, Matt Quackenbush said:
On 6/2/08 at 2:07 PM, Matt Quackenbush said:
<uform:field label="My Label" name="fieldname" isRequired="true" type="select">
<cfloop query="myQuery">
<uform:option display="#myQuery.myDisplayField[currentRow]#"
value="#myQuery.myValueField[currentRow]#"
isSelected="#myQuery.myValueField[currentRow] EQ form.fieldname#" />
</cfloop>
</uform:field>
On 6/2/08 at 6:05 PM, Jonathan van Zuijlekom said:
On 6/3/08 at 5:59 AM, Tom K said:
- Thanks - I didn't really think that I could do a conditional statement in this syntax:
ischecked="#form.ispublic EQ 1#" etc..
That solves a lot of my "hacking"!
On 6/4/08 at 6:38 PM, Dan said:
Also, is there a way to generate a multiple select box?
On 6/4/08 at 6:57 PM, Matt Quackenbush said:
Multiple select is not currently supported as-is. I have added it to the feature requests for the next round of updates. :-)
On 6/4/08 at 7:27 PM, Dan said:
##newsletter:checked
##newsletter-1:checked
$('newsletter').checked
$('newsletter-1').checked
The newsletter checkbox and email field combination are common on our site and we also are hoping to make a state/province dropdown required if the user chooses USA, otherwise if they choose any other country a "Other State/Province" text box magically appears and the state/province dropdown disappears.
You can check out an example at http://www.akextremeadventures.com/make_reservatio.... If you choose USA, Canada or Australia you then must choose from the state/province dropdown. Otherwise you get a text box. Of course, these forms took a lot of time to design and write the JS code, which is why I'm looking into your Uni-Form tag.
Here is the code just in case I did something dumb.
<div class="formContainer">
<!--- build the form --->
<uform:form action="action.cfm"
id="myForm"
submitValue="Send"
showCancel="false"
loadValidation="true"
loadjQuery="true">
<uform:fieldset legend="Your Info">
<uform:field label="Name"
name="name"
isRequired="true"
type="text"
validation="required" />
<uform:field label="Newsletter Sign Up" isRequired="true" validation="required" name="newsletter" type="checkboxgroup">
<uform:checkbox label="Yes I want to sign up for the newsletter" value="email" />
</uform:field>
<uform:field label="Email Address"
name="email"
isRequired="true"
type="text"
validation="$('newsletter-1').checked email" />
</uform:fieldset>
</uform:form>
</div>
Thanks,
Dan
On 6/4/08 at 7:43 PM, Matt Quackenbush said:
It appears that I need to add a couple more things to the validation support in order to handle rules. As-is it will handle only the simple validations that are built-in to the plugin. It will be a little bit before I can take a good look at it, but I *think* it should be something I can bang out pretty quickly once I get a second to look into it. Hopefully I'll be able to do so in the next week or so.
In the meantime, you (or anyone else) should be able to write your rules externally (in a <script> block as you normally would), and also externally load the validation script that comes with the download. This should still allow full integration with the Uni-Form markup, with minimal extra code.
On 6/4/08 at 7:47 PM, Dan said:
Thanks again for the prompt response and cool new tool.
Dan
On 6/5/08 at 5:05 PM, Dan said:
window.onload = function() {
$("#contactEmail").rules("add", {
required: "#newsletter-1:checked",
email: true
});
}
On 6/5/08 at 5:11 PM, Matt Quackenbush said:
1) try this for your function...
$(document).ready(function() {
$("#contactEmail").rules("add", {
required: "#newsletter-1:checked",
email: true
});
});
2) the isRequired argument on the tag should have zero affect on your validation routines. All it does (if set to true) is place the * next to the field, denoting it as being required.
On 6/5/08 at 6:30 PM, Dan said:
On 6/10/08 at 9:28 PM, Jim Priest said:
On 6/11/08 at 4:00 PM, Matt Quackenbush said:
On 6/12/08 at 11:45 AM, Matt MacDougall said:
-Matt
On 6/12/08 at 2:55 PM, Matt Quackenbush said:
On 2/3/09 at 12:11 PM, George said:
I am not getting any errors. I am getting four select boxes when I was only expecting 2 and when I select the first box the on change event never fires to load the second box.
On 2/3/09 at 8:11 PM, Matt Quackenbush said:
<script>
// load cities based upon the state
$(function () {
var state = $('#state');
var city = $('#city');
state.selectChain({
target: city,
url: '<cfoutput>#xit.loadCitiesByState#</cfoutput>',
type: 'post',
key: 'city',
selectedValue: '<cfoutput>#address.getCity()#</cfoutput>',
data: { ajax: true, anotherval: "anotherAction" }
}).trigger('change');
});
</script>
<uform:field label="State" name="state" type="select" isRequired="yes">
<uform:states-us fieldName="state" struct="#event.getCollection()#" defaultState="#address.getState()#" />
</uform:field>
<uform:field label="City" name="city" type="select" isRequired="yes">
<option value="">-- Select State First --</option>
</uform:field>
Plugin Link: http://remysharp.com/2007/09/18/auto-populate-mult...
On 2/4/09 at 8:53 AM, George said:
Why did you use this in the first select uform:states-us? Was it because this field type was setup to take a struct as a parameter? And finally, what is going on with
data: ajax: true, anotherval: anotherAction
On 2/4/09 at 4:31 PM, Matt Quackenbush said:
I'm not sure what you're asking about with the uform:states-us question.