469,292 Members | 1,438 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,292 developers. It's quick & easy.

CFGrid OnValidate Validation Applet Example

Does anyone have a sample validation applet they could share? I am using cfgrid (non-flash) and need to validate a date field and a float field. I can't find any non-flash examples and I need to get this working ASAP. Thanks in advance.
Feb 25 '08 #1
7 6915
acoder
16,027 Expert Mod 8TB
See this link from the docs. If you get stuck, post your code.
Feb 25 '08 #2
See this link from the docs. If you get stuck, post your code.
I'm using a very simple validation just to make sure I'm doing it correctly. When I display the value object in the js module, I get a complex value. Do I need to somehow parse that value in order to determine the row data? Also, when I display the field object, I only get [object]. Any lead you can give me will be greatly appreciated.

Coldfusion
Expand|Select|Wrap|Line Numbers
  1.  
  2. <cfgrid name="TRGrid" query="grid" width="725" height="300" onchange="showSave();"
  3. onvalidate="validateFields" 
  4. rowheaders="yes" colheaders="yes" colheaderalign="center" colheaderbold="yes"
  5. selectmode="edit" insert="yes" delete="yes" 
  6. insertbutton="Add New Task" deletebutton="Delete Selected Task" >
  7.     <cfgridcolumn name="CatDesc" header="Category" width="125" select="no">
  8.     <cfgridcolumn name="TaskID" header="Task" width="250" values="#TaskIDList#" valuesdisplay="#TaskDescList#">
  9.     <cfgridcolumn name="ActivityID" header="Activity" width="165" values="#ActIDList#" valuesdisplay="#ActDescList#">
  10.     <cfgridcolumn name="ActivityDate" header="Date" width="75" dataalign="right" mask="mm/dd/yy" type="string_nocase">
  11.     <cfgridcolumn name="Hours" header="Hours" width="65" dataalign="right" numberformat="00.00" type="numeric">
  12.     <cfgridcolumn name="ID" display="no" width="100">
  13.     <cfgridcolumn name="EmpID" display="no" header="Employee" width="100">
  14.     <cfgridcolumn name="CategoryID" display="no" header="Category" width="100">
  15. </cfgrid>
  16.  
javascript:
Expand|Select|Wrap|Line Numbers
  1. function validateFields(form, field, value) {
  2.     //Check for date field
  3.      if (field == "ActivityDate") {
  4.         if(value.length < 8) {
  5.             alert("A date value is incorrect. Please enter the date as mm/dd/yy.");
  6.             return false;
  7.         }
  8.         else {
  9.             return true;
  10.         }
  11.     }
  12.     //check for other fields here.
  13.     else {
  14.         return true;
  15.         }
  16. }
Feb 26 '08 #3
acoder
16,027 Expert Mod 8TB
Just to confirm, this cfgrid is within a cfform?
Feb 26 '08 #4
Just to confirm, this cfgrid is within a cfform?
Yes. The cfform contains a 2-column table: left side has some filtering links, right column displays the grid. I use a stored procedure to fill the grid and custom queries code to insert/delete/update the rows. Everything works great. Now I'm just trying to validate the date and hours columns.
Feb 27 '08 #5
acoder
16,027 Expert Mod 8TB
When I display the value object in the js module, I get a complex value. Do I need to somehow parse that value in order to determine the row data? Also, when I display the field object, I only get [object].
Do you mean an alert here? You could try checking the HTML/JavaScript source to see what's passed through.

PS. I don't program with onValidate much.
Feb 28 '08 #6
Do you mean an alert here? You could try checking the HTML/JavaScript source to see what's passed through.

PS. I don't program with onValidate much.
I just put an alert there for testing only. I did check the values being passed and the string is some type of concatenated list. I don't know if I'm suppose to parse it or use some special technique to determine the grid column and grid value being checked.
Feb 29 '08 #7
acoder
16,027 Expert Mod 8TB
Can you show an example of a list that is passed?
Feb 29 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Put 030516 in email subj to get thru | last post: by
1 post views Thread by Tormod Omholt-Jensen | last post: by
2 posts views Thread by Put 030516 in email subj to get thru | last post: by
1 post views Thread by 418928 | last post: by
2 posts views Thread by Richard Maher | last post: by
3 posts views Thread by javaBookWorm | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.