Here is a new version of the checkFieldSet UDF. Brett found a few issues in my UDF. First - I accidently left in a hard coded form name, donations. This was from the project I was working on. Secondly, I thought there was no way to get the particular error message for a field. Brett showed that you could get it simply by using #f#.errorString, where f is the field name. He also showed that if you put 'Error' in your second argument in the alert call it marks it as an Error window.
So - I took his code mod and modded it some more. Now the error message isn't an optional argument - it is the combination of all the error messages in the current field set. (By that I simply mean the page, or tab/accordion.)
So - here is the latest version. Enjoy.
<cfargument name="fields" type="string" required="true" hint="Fields to search">
<cfargument name="form" type="string" required="true" hint="Name of the form">
<cfargument name="ascode" type="string" required="true" hint="Code to fire if all is good.">
<cfset var vcode = "">
<cfset var f = "">
<cfsavecontent variable="vcode">
var ok = true;
var msg = "";
<cfloop index="f" list="#arguments.fields#">
<cfoutput>
if(!mx.validators.Validator.isValid(this, '#arguments.form#.#f#')) { msg = msg + #f#.errorString + '\n'; ok=false; }
</cfoutput>
</cfloop>
</cfsavecontent>
<cfset vcode = vcode & "if(!ok) mx.controls.Alert.show(msg,'Error'); ">
<cfset vcode = vcode & "if(ok) #ascode#">
<cfset vcode = replaceList(vcode,"#chr(10)#,#chr(13)#,#chr(9)#",",,")>
<cfreturn vcode>
</cffunction>


Comment 1 written by Brett Liotta on 12 February 2005, at 1:41 AM
I realized that our projects are a bit different so I had to mod the function a little bit more to work for my purposes. Here are the differences in our projects.
Yours is a flash form with multiple accordion tabs. Each accordion tab is a separate step and you can only move forward in the tabs if each tab passes form validation.
Now here's mine: you can move around in the tabs at any point (not separate steps) in the data entry process. The fields on each tab are submitted as one step when all tabs pass form validation rules. This is a bit more complicated and I'm still working out a solution. I also have some fields that are required only when some other field has been filled out (dynamic validation). It's a pretty complicated Data Entry process. I really like the whole flash concept, but yeah I do see a bit of a learning curve with ActionScript. I guess it was just a matter of time that I was going to have to learn it. What better time than this?
Or, I can always go back to regular forms or XML forms..
Any thoughts? Kind of an open forum post, than a specific problem.
The more I think about it, the more I'm thinking it might be easier to just do it the step way like you.
Comment 2 written by Steve Moore on 14 February 2005, at 2:30 PM
Comment 3 written by Raymond Camden on 14 February 2005, at 2:34 PM
Comment 4 written by johnb on 16 February 2005, at 4:48 AM
Comment 5 written by Raymond Camden on 16 February 2005, at 8:57 AM
accordion1.selectedIndex=2
It should be simular for tabs. Note, "accordian1" is the name value for the accordion.
Comment 6 written by johnb on 16 February 2005, at 9:04 AM
Comment 7 written by johnb on 16 February 2005, at 12:22 PM
Comment 8 written by Raymond Camden on 16 February 2005, at 3:39 PM
Comment 9 written by pim on 25 February 2005, at 12:40 PM
Comment 10 written by Brett Liotta on 25 February 2005, at 2:14 PM
<cfform type="flash"...>
<cfformgroup type="tabnavigator" selectedIndex="#url.tab#">
<cfformgroup type="page" label="General">
some cfinputs..
</cfformgroup>
<cfformgroup type="page" label="Special Instructions">
some cfinputs..
</cfformgroup>
</cfformgroup>
</cfform>
so whats going to happen here is say the variable url.tab is a 1. the flash form will open with the second tab selected (viewable). Keep in mind almost everything in flash is based on 0 now being the first in an array (b/c of actionscript). so [selectedIndex="0"] will be referencing the first tab and 1 will be referencing the second tab, etc.
Comment 11 written by Brett Liotta on 25 February 2005, at 2:15 PM
Comment 12 written by cfm_pedawan on 1 March 2006, at 5:03 PM
I am sure this is a silly question.
I have created a 6 page multi-step CFFORM and I want to validate one of the tabs to ensure a users answser at least one question. Unfortunatly the spec will not let me use a required say text field that will take a Y or N value.
So I searched the net and found this partial solution.
But how do you use this UDF with flash forms. Does it have to within the tab/page being validated to be called? I currently have it above my <cfform> and I am not getting the alert messages.
Here is my code for the executing button on the tab I am validating.
<!--- Push To Next Tab --->
<cfinput value="Continue..." onClick="tnav.selectedIndex=5;" type="button" name="tab5_btn" width="100">
Any help is appreciated.
Thanks..
Comment 13 written by Raymond Camden on 1 March 2006, at 5:06 PM
Comment 14 written by Raymond Camden on 1 March 2006, at 5:07 PM
http://ray.camdenfamily.com/index.cfm?mode=
entry&entry=F002F1C6-C060-F0E5-EB698A2C0202209D
Comment 15 written by cfm_pedawan on 1 March 2006, at 5:08 PM
<!--- Push To Next Tab --->
<cfinput value="Continue..." onClick="#checkFieldSet("field1,field2","formname","tnav.selectedIndex=4")#" type="button" name= "tab4_btn" width="100">
Thanks...
Comment 16 written by cfm_pedawan on 1 March 2006, at 7:07 PM
- The function is included
- I am calling the function in my the tab that I need the field validated?
- ???
Any Thoughts? Any is appreciated...
<code>
<!--- Begin Tab Field Check Function --->
<cffunction name="checkFieldSet" output="false" returnType="string">
<cfargument name="fields" type="string" required="true" hint="Fields to search">
<cfargument name="form" type="string" required="true" hint="Name of the form">
<cfargument name="ascode" type="string" required="true" hint="Code to fire if all is good.">
<cfset var vcode = "">
<cfset var f = "">
<cfsavecontent variable="vcode">
var ok = true;
var msg = "";
<cfloop index="f" list="#arguments.fields#">
<cfoutput>
if(!mx.validators.Validator.isValid(this, '#arguments.form#.#f#')) { msg = msg + #f#.errorString + '\n'; ok=false; }
</cfoutput>
</cfloop>
</cfsavecontent>
<cfset vcode = vcode & "if(!ok) mx.controls.Alert.show(msg,'Error'); ">
<cfset vcode = vcode & "if(ok) #ascode#">
<cfset vcode = replaceList(vcode,"#chr(10)#,#chr(13)#,#chr(9)#",",,")>
<cfreturn vcode>
</cffunction>
<!--- End Tab Field Function --->
<!--- Begin CFFORM --->
<cfform format="flash" width="550" height="400" timeout="1000" skin="haloblue" name="demotab">
<cfformgroup type="panel" label="Multi Step Form" width="400" height="300" style="marginRight:2; font-size:12px; color:##000000; headerColors:##FFFFFF; dropShadow:0; headerHeight:22; panelBorderStyle:'roundCorners'; backgroundColor:##FFFFFF">
<!--- Begin Tab Navigation Box --->
<cfformgroup type="tabnavigator" id="tnav" name="tnav">
<!--- Begin Tab 1 --->
<cfformgroup type="page" label="Tab1" width="650" height="300">
<!--- Headers --->
<cfformitem type="html">
<font size="-1" color="##666666">
<br>
<b>Contact Info:</b><br>
</font>
</cfformitem>
<!--- Form Fields --->
<cfinput type="text" name="contName" label="Name:" size="20" value="" required="yes" message="Please Enter Contact First Name">
<cfinput type="text" name="contEmail" label="Email:" size="20" value="" required="yes" message="Please Enter Valid Contact Email Address" validate="email">
<cfinput type="text" name="contPhone" label="Phone:" size="20" value="">
<!--- Push To Next Tab --->
<cfinput value="Continue..." onClick="tnav.selectedIndex=1;" type="button" name="tab1_btn" width="100">
</cfformgroup>
<!--- End Tab 1 --->
<!--- Begin Tab 2 --->
<cfformgroup type="page" label="Tab2" width="400" height="300">
<!--- Header --->
<cfformitem type="html">
<font size="-1" color="##666666">
<br><b>Select Geography: (Select all that apply)</b>
</font>
</cfformitem>
<!--- Form Fields --->
<cfformgroup type="tile">
<cfinput type="checkbox" name="Amer1" label="North America">
<cfinput type="checkbox" name="Amer2" label="South America">
</cfformgroup>
<cfinput type="text" name="Other" label="Other:" size="10">
<!--- Push To Next Tab --->
<cfinput type="button" name= "tab2_btn" value="Val_This_Tab" onClick="#checkFieldSet("Amer1,Amer2,Other","demotab","tnav.selectedIndex=2")#" width="100">
</cfformgroup>
<!--- End Tab 2 --->
<!--- Begin Finish Tab --->
<cfformgroup type="page" label="Finish" width="400" height="300">
<!--- Header --->
<cfformitem type="html">
<font size="-1" color="##666666">
<br>
<b>Comments:</b><br>
</font>
</cfformitem>
<!--- TextArea field --->
<cftextarea name="Comments" wrap="virtual" rows="5" cols="30" validate="maxlength" validateAt="onBlur" maxlength="500">
</cftextarea>
<!--- Submit Request --->
<cfinput type="submit" name="submit" value="Submit Request">
</cfformgroup>
<!--- End Finish Tab --->
</cfformgroup>
<!--- Begin Tab Navigation Box --->
</cfformgroup>
</cfform>
<!--- End CFFORM --->
</code>
Comment 17 written by cfm_pedawan on 9 March 2006, at 7:43 PM
Could someone post some example code of how you got the UDF to work? Please post UDF + CFFORMS... I am looking over my code and I can't seem to figure out why the alerts are not popping up etc when no field is select on X tab. I have posted my code in the post above. Any help would be much appreciated.
</thanks>
P.S
I am really weak with all the AS stuff, need to catch up "FLEX TIME"
Comment 18 written by Rod Kesselring on 27 November 2006, at 10:35 AM
Comment 19 written by Rod Kesselring on 27 November 2006, at 10:37 AM
[Add Comment] [Subscribe to Comments]