Okay as promised Will, here's what I do.  It's most certainly not the most
efficient method, since it's my first go 'round, but it does what I ask it
to.  I've added a few comments inline for you.  (After pasting in here I
can't even tell what's going on--and I wrote it!  Paste this into your
editor to get a clearer view...) 

A) Here is a snippet of the original html.  It simply presents a
field/label.

<div class="row" id="shipto_location">
        <div class="required">Ship-to location:</div> <input type="text"
maxlength="75"> <!--- these inputs are all autocomplete text fields --->
        <img src="" width="14" height="14" class="ico">  <!--- call $(".row
img").hide() on page load --->
</div>

B) Here is the jQuery bit that binds a behavior to the blur event.  In my
case this comes from a Taconite response, but I think you'd need it in your
document.ready() function for testing.  

$("#shipto_location input").blur(function (){
        /* when the input within #shipto_location loses focus, pass the name
of the input and the value of the customer name input to be validated */
        validateField('shipto_location',$("#customer_name input").val());
});

C) As posted before, here is the validateField function called by part B
above.

function validateField(field, criteria){
        /* change the src of the row's icon (in this example,
#shipto_location img.ico) to the loading spinny */
        $("#"+field+"
img.ico").attr("src","/images/office/ico-loading.gif");
        /* pass the name of the field to validate, the value of said field,
and the value of an optional criteria (in this case, $("#customer_name
input").val()) */
        $.get("/gateway/validate.cfm?field="+field+"&value="+$("#"+field+"
input").val()+"&criteria="+criteria,            
                        function(response){
                                /* evaluate the json response */
                                response = eval("("+response+")");
                                /* display the appropriate icon; showIcon
can be called after either ajax or local validation */
                                showIcon(field,response.pass,response.msg);
                });     
}

D) Here's the relevant snippet from validate.cfm:

<!--- the cfswitch expression is url.field --->
<cfcase value="shipto_location" delimiters="|">
        <cfquery name="q" datasource="Yard">
                select s.shipto_id
                from  shipto_locations as s inner join
                      customers as c on s.customer_id = c.customer_id
                where (s.shipto = <cfqueryparam value="#url.value#">) and
(c.customer = <cfqueryparam value="#url.criteria#">)
        </cfquery>
        <cfif q.recordcount GT 0>
                <!--- The value of st["pass"] is set to false by default
above the cfswitch block --->
                <cfset st["pass"]=true>
        <cfelse>
                <cfset st["msg"]="'#url.value#' is not a valid
#url.criteria# location.">
        </cfif>
</cfcase>
...
<!--- after the cfswitch expression, display the struct in json format (you
have json.cfc, right?) --->
<cfoutput>#json.encode(st)#</cfoutput>

You can see the result of all this:
http://paul.malan.org/jQuery/validation-example.png.  

(You may also get some use out of Chris Jordan's new CF/jQuery function set
- http://cjordan.us/ - for local validation.)

Let me know if this helps or confuses...
Paul

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Rick Faircloth
Sent: Monday, March 12, 2007 3:35 PM
To: 'jQuery Discussion.'
Subject: Re: [jQuery] Calling all CF'ers... et al...

Paul, could I impose upon you to strip your example code
down to handling one field?  I don't understand everything you've
got there, and what it all refers to.

Also, could you send an example of your cf processing for a field?

This would give me enough to work on and test.  Hopefully I can figure
it out from there.

Thanks for all your help!

Rick

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Paul
Sent: Monday, March 12, 2007 5:44 PM
To: 'jQuery Discussion.'
Subject: Re: [jQuery] Calling all CF'ers... et al...

What you described is basically what I do, Rick--not because Jorn's plugin
didn't work but because many of my form fields are validated against each
other, and database interaction is required to make that decision. (e.g.,
the validity of field Y depends on the value already entered in field X.)

Below is the validate function I call onBlur from each input.  It first sets
the field's status icon to a loading spinny, then requests validation from a
CFM file, passing the value of the current field as well as the value of the
dependent criteria, which CF handles (cfswitch/cfcase) depending on which
field is passed.  The callback receives the response and shows either a
success or error icon with a descriptive error attached in a stylish little
error message balloon.

I don't know if this is the smartest method--I'm pretty new to jQuery
myself--but it has worked very well and provides the flexibility I need.

HTH,
Paul

function validateField(field, criteria){
        $("#"+field+"
img.ico").attr("src","/images/office/ico-loading.gif");
        $.get("/gateway/validate.cfm?field="+field+"&value="+$("#"+field+"
input").val()+"&criteria="+criteria,
                function(response){
                        response = eval("("+response+")");
                        showIcon(field,response.pass,response.msg);
        });     
}





_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to