cfUniForm v3.2 - Bug Fixes and New Error Message Array Support

Posted on February 25, 2009 at 10:00 PM in Uni-Form Tag Library

Well, after several months of getting no love, cfUniForm has seen a flurry of activity in the last week. This evening I have released the latest and greatest, v3.2, which addresses a couple of bugs and adds a brand new enhancement.

Bug Fix: Radio Buttons and Checkboxes

The v3.2 release fixes an issue where radio buttons and checkboxes were ignored by client-side validation when the 'isRequired' attribute was set to true. Here's a quick example of the proper use:

  1. <uform:field label="Age Group" name="age" type="radio" isRequired="true">
  2. <uform:radio label="18-25"
  3. value="1"
  4. isChecked="#form.age EQ 1#" />
  5. <uform:radio label="26-40"
  6. value="2"
  7. isChecked="#form.age EQ 2#" />
  8. <uform:radio label="41-60"
  9. value="3"
  10. isChecked="#form.age EQ 3#" />
  11. <uform:radio label="61+"
  12. value="4"
  13. isChecked="#form.age EQ 4#" />
  14. </uform:field>

This release also includes another bug fix related to radio buttons and checkboxes. (Can you tell that I don't use them very much?) This bug was related to the validation plugin highlighting radio/checkbox fields when client-side validation fails.

New Feature: Error Message Array

One of the items that honestly really annoyed me when I first wrote cfUniForm was that I couldn't use a standard array of error messages and provide the proper inline display. The reason being that in order to match the errors up with their respective fields, the field name has to be known. This led me to use a struct of messages with cfUniForm.

While using a struct solved one problem (inline display), it created another issue: displaying error messages at the top of the form were displayed in whatever order ColdFusion saw fit to arrange the struct keys in - typically alphabetical. It wasn't a show-stopper, since I tend to use a generic error message at the top of a form and then display the specific messages inline. However, it has always been kind of an annoyance to me, so the other day I decided to rid myself of said annoyance.

The cfUniForm v3.2 release now supports two ways of providing the error messages to the form tag:

  1. A struct with key/value pairs, where the key is the field (property) name, and the value is the error message to display, or
  2. An array of structs, where each index of the array contains a struct with two keys:

    1. 'property': the name of the property (field) to which the error message belongs, and
    2. 'message': the error message to display

NOTE #1: The struct option is identical to what has always been in cfUniForm, so error message handling is backward compatible with previous releases.

Here's an example of how to use an array of structs:

  1. <cfscript>
  2. errs = [];
  3. st = {property="email",message="Please enter your Email Address."};
  4. arrayAppend(errs, st);
  5. st = {property="password",message="The passwords do not match."};
  6. arrayAppend(errs, st);
  7. st = {property="email",message="The Email Address is invalid."};
  8. arrayAppend(errs, st);
  9. </cfscript>

NOTE #2: If you provide an array to the errors attribute, it *must* be an array of structs that follows the convention shown above. If not, an exception will be thrown.

You can see this new feature in action in the error message array demo.

I hope that this new feature will make your forms even easier to manage.

UPDATE (2/27/09)

The v3.3 release contains updates that support either a 'property' key OR a 'field' key.

Comments
(Comment Moderation is enabled. Your comment will not appear until approved.)

On 2/26/09 at 7:11 PM, Sana said:

@Matt

Is it possible to add rule like this
<uform:field label="Email address"
name="Email"
type="text"
Rule="
{
required: true,
email: true
}
"

may be this is another enhancement requesst for uniform :)

On 2/26/09 at 7:16 PM, Matt Quackenbush said:

@ Sana - For that you'd do the following:

<uform:field label="Email Address"
name="Email"
type="text"
isRequired="true"
inputClass="email">

On 2/27/09 at 11:45 AM, Geoff said:

Hi Matt,

Not sure if you've fiddled with the illudium code generator thing, but it produces an array of structs for errors, something like this:

<cfif (NOT len(trim(getTitle())))>
   <cfset thisError.field = "Title" />
   <cfset thisError.type = "required" />
   <cfset thisError.message = "Title is required" />
   <cfset arrayAppend(errors,duplicate(thisError)) />
</cfif>

I don't think this is a de-facto standard for errors by any means, but for me, combining cfUniForm and the illudium generator for the quick generation of beans and forms for CRUD operations would be fantastic...

Any chance an error struct like that could be supported off the bat? (Yes, I could write something to change the keys of the struct, or change your code to accept a different error format, but it'd be nice to have something standardized if poss!)

On 2/27/09 at 4:39 PM, Matt Quackenbush said:

@ Geoff - I have never used Illudium, so I use a different convention. However, it's a worthy change, so I have updated the v3.3 download to support either convention. Thanks for the suggestion.
CodeBassRadio

Latest Articles

Eventually something really brilliant and witty will appear right here.

Calendar

May 2026
S M T W T F S
« Apr  
          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            

Subscribe

Enter a valid email address.

The Obligatory Wish List