House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Sort #FORM# by value?

  << Previous Post |  RSS |  Tree View |  Sort Oldest First |  Subscribe to this Group Next >> 

Sort #FORM# by value?

It's working perfect Charlie, thanks.  One small change I made on the Morgan Senkal 05/20/2004 07:50 PM
Morgan: Charlie Griefer 05/20/2004 07:02 PM
Ah, thanks for clearing that up.  I was testing kArray[i] instead Morgan Senkal 05/20/2004 06:52 PM
if you want it to insert only numeric values...the UDF should look like: Charlie Griefer 05/20/2004 06:27 PM
Doesn't matter, as long as I can access the name in relation to the value.  Morgan Senkal 05/20/2004 06:25 PM
when you say you need to retain the original key name...how so?  a 2d Charlie Griefer 05/20/2004 06:19 PM
Ok, for starters I tried adding a simple if statement like so: Morgan Senkal 05/20/2004 06:01 PM
I suppose I should have given more information, sorry :-(  But to Morgan Senkal 05/20/2004 05:57 PM
Hi Morgan: Charlie Griefer 05/20/2004 12:40 AM
Any ideas?  You would think that StructSort would be the answer but Morgan Senkal 05/19/2004 03:41 PM

05/20/2004 07:50 PM
Author: Morgan Senkal Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32626#163869 It's working perfect Charlie, thanks.  One small change I made on the second line of the function: Changed: var stForm = f; Changed To: var stForm = Duplicate(f); I wanted to leave the original #form# intact for further processing.  On testing the code I found that leaving out the Duplicate() function did not break the reference. ----- Excess quoted text cut - see Original Post for more -----
05/20/2004 07:02 PM
Author: Charlie Griefer Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32626#163867 Morgan: This seems to do it: <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <cfscript>   function sortForm(f) {    var sortArray = arrayNew(2);    var stForm = f;       var keys = structKeyArray(stForm);    var sortedKeys = "";       for (i=1; i LTE #arrayLen(keys)#; i=i+1) {     if (NOT isNumeric(stForm[keys[i]])) {      structDelete(stForm, keys[i]);     }    }    sortedKeys = structSort(stForm, 'numeric');       for (i=1; i LTE #arrayLen(sortedKeys)#; i=i+1) {     sortArray[arrayLen(sortArray)+1][1] = sortedKeys[i];     sortArray[arrayLen(sortArray)][2] = stForm[sortedKeys[i]];    }    return sortArray;   } </cfscript> </head> <body> <cfparam name="form.field1" default="foo"> <cfparam name="form.field2" default="bar"> <cfparam name="form.field3" default="12"> <cfparam name="form.field4" default="foobar"> <cfparam name="form.field5" default="4"> <cfparam name="form.field6" default="barfoo"> <cfparam name="form.field7" default="8"> <cfdump var="#form#" label="this is the original form"> <cfset formSorted = sortForm(form)> <cfdump var="#formSorted#" label="this should be sorted"> </body> </html> let me know if that works out. Charlie
05/20/2004 06:52 PM
Author: Morgan Senkal Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32626#163866 Ah, thanks for clearing that up.  I was testing kArray[i] instead of stForm[kArray[i]].  As for the keys, as I mentioned above there should be no chance of having duplicate numeric values returned, so I can just match up the values to their keys in the original form now that they are in order. ----- Excess quoted text cut - see Original Post for more -----
05/20/2004 06:27 PM
Author: Charlie Griefer Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32626#163863 if you want it to insert only numeric values...the UDF should look like: <cfscript> function sortForm(stForm) {   var formValueArray = arrayNew(1);   var kArray = structKeyArray(stForm);   for (i=1; i LTE arrayLen(kArray); i=i+1) {    if (isNumeric(stForm[kArray[i]])) {     formValueArray[arrayLen(formValueArray)+1] = stForm[kArray[i]];    }    }   temp = arraySort(formValueArray, 'numeric');   return formValueArray; } </cfscript> this does NOT yet retain the form field name.  still not sure how you intend to handle that. ----- Excess quoted text cut - see Original Post for more ----- the cfdump I'm getting back for the FORM element:
05/20/2004 06:25 PM
Author: Morgan Senkal Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32626#163862 Doesn't matter, as long as I can access the name in relation to the value.  On second thought, I think the way I coded the form, I don't believe that it is possible for there to be repeat values.  (all the form values in question are from checkboxes, so I can control the values sent).  So actually the code you started will work, as long as it only includes those values that are numeric (and not empty), so I can do a numeric sort. ----- Excess quoted text cut - see Original Post for more -----
05/20/2004 06:19 PM
Author: Charlie Griefer Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32626#163860 when you say you need to retain the original key name...how so?  a 2d array? a structure? Charlie > I suppose I should have given more information, sorry :-(  But to clarify: I only want to pull out FORM values which are numeric and order those.  I also need to somehow retain the key name associated to each value.  It's a good start tho thanks much Charlie!  Perhaps you and I can fiddle with it and see where we get... ----- Excess quoted text cut - see Original Post for more -----
05/20/2004 06:01 PM
Author: Morgan Senkal Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32626#163857 Ok, for starters I tried adding a simple if statement like so: if (isNumeric(kArray[1])) {   formValueArray[arrayLen(formValueArray)+1] = stForm[kArray[i]]; } But apparently it doesn't recognize any of the values as numbers.  This is the cfdump I'm getting back for the FORM element: ACTIONDATE1   ACTIONDATE2   ACTIONITEMDESCRIPTION   ACTIVITYTYPE   ACTIVITYTYPEORDER 5   BUSINESSUNIT   BUSINESSUNITORDER 3   DATE1 5/13/2004   DATE2 5/20/2004   FIELD1 foo   FIELD2 bar   FIELD3 foobar   FIELD4 barfoo   FIELDNAMES ISSUEDESCRIPTIONORDER,ISSUEDESCRIPTION,ISSUEOUTCOME,ACTIONITEMDESCRIPTION,GENTEXT,ACTIVITYTYPEORDER,ACTIVITYTYPE,DATE1,DATE2,TRIBEORDER,TRIBE,BUSINESSUNITORDER,BUSINESSUNIT,PARTICIPANT,ISSUECATEGORY,PRIORITY,PROJECTORDER,PROJECT,ISSUESTATUSORDER,ISSUESTATUS,ACTIONDATE1,ACTIONDATE2,QUERYNUMBER,QUERYTITLE,QUERY0 GENTEXT   ISSUECATEGORY   ISSUEDESCRIPTION   ISSUEDESCRIPTIONORDER 9   ISSUEOUTCOME   ISSUESTATUS   ISSUESTATUSORDER 10   PARTICIPANT   PRIORITY   PROJECT   PROJECTORDER 4   QUERY0 Run Query   QUERYNUMBER 0   QUERYTITLE Custom Query   TRIBE   TRIBEORDER 1   So there are indeed numbers in there, but the question of whether they are 'numeric' objects is apparently no.  Not sure the best way to proceed at this point... ----- Excess quoted text cut - see Original Post for more -----
05/20/2004 05:57 PM
Author: Morgan Senkal Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32626#163855 I suppose I should have given more information, sorry :-(  But to clarify:  I only want to pull out FORM values which are numeric and order those.  I also need to somehow retain the key name associated to each value.  It's a good start tho thanks much Charlie!  Perhaps you and I can fiddle with it and see where we get... ----- Excess quoted text cut - see Original Post for more -----
05/20/2004 12:40 AM
Author: Charlie Griefer Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32626#163745 Hi Morgan: Might be a better/more efficient way, but threw together a quick UDF that seems to work: <html> <head>   <title></title>   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />      <cfscript>     function sortForm(stForm) {       var formValueArray = arrayNew(1);       var kArray = structKeyArray(stForm);              for (i=1; i LTE arrayLen(kArray); i=i+1) {    formValueArray[arrayLen(formValueArray)+1] = stForm[kArray[i]];       }              temp = arraySort(formValueArray, 'text');       return formValueArray;     }   </cfscript> </head> <body> <cfparam name="form.field1" default="foo"> <cfparam name="form.field2" default="bar"> <cfparam name="form.field3" default="foobar"> <cfparam name="form.field4" default="barfoo"> <cfdump var="#form#"> <cfset formValueArray = sortForm(form)> <cfdump var="#formValueArray#"> </body> </html> Hope that helps. Any ideas?  You would think that StructSort would be the answer but nope.   TIA! -Morgan
05/19/2004 03:41 PM
Author: Morgan Senkal Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32626#163708 Any ideas?  You would think that StructSort would be the answer but nope.   TIA! -Morgan
<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 24, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     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     

Designer, Developer and mobile workflow conference