QuackFuzed.com is the personal ColdFusion coding blog of Matt Quackenbush. It exists primarily as a place for the author to learn, and hopefully to assist others in learning and/or avoiding some of the same pitfalls and mistakes. (Quack certainly makes enough mistakes daily to make up for the entire ColdFusion community.)

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...

[Continue Reading]

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

On 6/2/08 at 6:34 AM, Tom K said:

Thanks for the update for this - Have been using v1 for a while now;
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:

Hi, in the demo the date of birth and time of birth don't seem to be working for Opera (9.27 nor 9.5beta2). For the date of birth I get two - 2 - dateobjects on top of eachtother of which only the "ugly" one is usable. The bottom one (the nicely formatted one with colours and stuff) doens't work. For the date of birth the up/down/left/right arrows don't work at all.

On 6/2/08 at 2:02 PM, Matt Quackenbush said:

@ Sebastiaan - I have no idea what is happening there, as I made no changes to the DatePicker and TimeEntry plugins. I can only guess that there must be some sort of conflict between them and the Uni-Form markup when it comes to Opera. I'm not making an attempt to start a browser war here, but since less than 1.5% of users world-wide use Opera, and in my applications far less than 0.5% are Opera users, I must admit that that doesn't concern me enough to spend time on. If you (or anyone else) knows what the conflict(s) might be, I'd be happy to add your fix to the code provided it does not break anything in the commonly used browsers.

On 6/2/08 at 2:07 PM, Matt Quackenbush said:

@ Tom K - I'm not sure exactly what you mean, but if I'm understanding correctly, you'd just do something like so...

<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:

@Sebastiaan. When I click the Date of Birth field I get 2 date pickers, with the ugly one on top. Both work fine (even the left, right, up and down arrows). When I click the text Select Date next to the field I only nicely formated one, the slide-out animation is even smoother than with FF3. This is with the latest 9.5 build.

On 6/3/08 at 5:59 AM, Tom K said:

@ Matt
- 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:

Is there any way to link 2 fields together with your tag? I have seen jQuery examples that use rules: { field2: { required: "#field1:checked" } } to make a second field required if the first field, a checkbox, is checked.

Also, is there a way to generate a multiple select box?

On 6/4/08 at 6:57 PM, Matt Quackenbush said:

@ Dan - As I stated in the post, I have not done any complex validation with jQuery's plugin, so I don't know for sure the answer to that question. Have you tried passing such rules into the 'validation' argument?

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:

I tried the following combinations in the validate attribute for the Email Address field with no success.

##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:

@ Dan - First off, no, you didn't do anything "dumb". :-)

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 &lt;script&gt; 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 I'll look into it. I'm new to jQuery so I'll have to play around with it a little.

Thanks again for the prompt response and cool new tool.

Dan

On 6/5/08 at 5:05 PM, Dan said:

I did figure out how to get this to work today. It took me longer to find the documentation than it did to correct my code. The only change I made to the code I posted earlier was to remove the isRequired and validation attributes from the email field. Then I added a script tag with the following code. This makes the email field required and it validates the field as an email address:

window.onload = function() {
   $("#contactEmail").rules("add", {
      required: "#newsletter-1:checked",
      email: true
   });
}

On 6/5/08 at 5:11 PM, Matt Quackenbush said:

@ Dan - Awesome! Thanks for posting the update. Just want to point out a couple of things...

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:

Yep, that works. I had to move the script block below the uform tags for now because I am letting your custom tag load jQuery.

On 6/10/08 at 9:28 PM, Jim Priest said:

I'm making heavy use of Jorn's validation plugin on a project. I'm curious with your tag - if I indicate a field is 'required' and disable JavaScript - does it fall back and use cfinput and do server side validation? That's been the big pain so far - writing the validations twice. One of these days I'll find time to mess around with Jaxer...

On 6/11/08 at 4:00 PM, Matt Quackenbush said:

@ Jim - No sir, the tags do not use cfinput. At this time server-side validation is not integrated with the tag library. However, there is a rumor floating around that an enhancement is in the works that would do just that.

On 6/12/08 at 11:45 AM, Matt MacDougall said:

Thanks for sharing this code. Just wanted to point out that the cfMgmt/common/images/icons directory is in subversion. When i tried to commit this to my local repository that bombed out. Removing the .svn directory in the icons directory allowed me to commit everything.

-Matt

On 6/12/08 at 2:55 PM, Matt Quackenbush said:

@ Matt - Thanks for pointing that out. I have removed it from the download, so it should be good to go now. :-)

On 2/3/09 at 12:11 PM, George said:

Hi Matt, I am plugging away with your library. I am trying to find a solution which will work inside your library to allow me to do 2 related selects? I looked at the cutom tag that Neil Weiss did called TwoSelectsRelated. Have you or any of your readers found a solution for 2 related selects which can work inside of cfuniform?
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:

@ George - I have successfully used the jQuery selectchain plugin (link below) to handle multiple selects, and it has worked nicely. Here's a brief example.

<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:

Hi Matt, Thanks for this code. I have 2 questions. First, what is this parameter doing in the javascript call? url: cfoutput>#xit.loadCitiesByState#cfoutput?
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:

@ George - The url attribute tells the javascript where to go and fetch the data from. The data attribute provides additional data to the controller (or the *.cfm page that is executing the request). I was just showing an example of passing a true|false (ajax: true) and a simple string value (anotherval: "anotherAction").

I'm not sure what you're asking about with the uform:states-us question.
CodeBassRadio

Latest Articles

Eventually something really brilliant and witty will appear right here.

Calendar

June 2008
S M T W T F S
« May   Jul »
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.

The Obligatory Wish List