CFGrid OnValidate Validation Applet Example

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prosetx
    New Member
    • Feb 2008
    • 4

    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.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    See this link from the docs. If you get stuck, post your code.

    Comment

    • prosetx
      New Member
      • Feb 2008
      • 4

      #3
      Originally posted by acoder
      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
      Code:
      						
      <cfgrid name="TRGrid" query="grid" width="725" height="300" onchange="showSave();"
      onvalidate="validateFields" 
      rowheaders="yes" colheaders="yes" colheaderalign="center" colheaderbold="yes"
      selectmode="edit" insert="yes" delete="yes" 
      insertbutton="Add New Task" deletebutton="Delete Selected Task" >
      	<cfgridcolumn name="CatDesc" header="Category" width="125" select="no">
      	<cfgridcolumn name="TaskID" header="Task" width="250" values="#TaskIDList#" valuesdisplay="#TaskDescList#">
      	<cfgridcolumn name="ActivityID" header="Activity" width="165" values="#ActIDList#" valuesdisplay="#ActDescList#">
      	<cfgridcolumn name="ActivityDate" header="Date" width="75" dataalign="right" mask="mm/dd/yy" type="string_nocase">
      	<cfgridcolumn name="Hours" header="Hours" width="65" dataalign="right" numberformat="00.00" type="numeric">
      	<cfgridcolumn name="ID" display="no" width="100">
      	<cfgridcolumn name="EmpID" display="no" header="Employee" width="100">
      	<cfgridcolumn name="CategoryID" display="no" header="Category" width="100">
      </cfgrid>
      Javascript:
      Code:
      function validateFields(form, field, value) {
      	//Check for date field
       	if (field == "ActivityDate") {
      		if(value.length < 8) {
      			alert("A date value is incorrect. Please enter the date as mm/dd/yy.");
      			return false;
      		}
      		else {
      			return true;
      		}
      	}
      	//check for other fields here.
      	else {
      		return true;
      		}
      }

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Just to confirm, this cfgrid is within a cfform?

        Comment

        • prosetx
          New Member
          • Feb 2008
          • 4

          #5
          Originally posted by acoder
          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.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by prosetx
            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.

            Comment

            • prosetx
              New Member
              • Feb 2008
              • 4

              #7
              Originally posted by acoder
              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.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Can you show an example of a list that is passed?

                Comment

                Working...