Solved

cfgridcolumn validation

Posted on 2010-09-21
8
1,346 Views
Last Modified: 2013-11-19
Hello experts.
I need help to validate editable cfgridcolumns.
I found a tutorial on this page:http://ajaxian.com/archives/coldfusion-8-grid-magic but i still have problems.
In this example the script is checking if it is a number.I also need to know how it works if i need to check for required fields,maxlength...
Any help?

My cfgrid:
 <cfgrid name="Kategoriegrid" format="html" pagesize="30" insert = "Yes"   sort="yes" width="100%"
    rowheaderbold="yes" colHeaderBold = "Yes"    pictureBar="yes" hspace="0" vspace="0"  bind="cfc:cfc.kategories.getKategories({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},{filtercolumn},{filter})" selectmode="edit" onchange= "cfc:cfc.kategories.updateKategories({cfGridAction},{cfgridrow},{cfgridchanged})">
      <cfgridcolumn name="TABLE_ID" header="Table_id"  select="no" display="false"/>
      <cfgridcolumn name="KAT_ID" header="Kat ID" width="30" numberformat="9" <!--- select="no" ---> display="false"/>
      <cfgridcolumn name="KAT_TEXT" header="Text" />
      <cfgridcolumn name="mobiles_sub_id" header="Mobile" select="no"/>
      <cfgridcolumn name="LangID" header="LangID"  select="no"/>
      
   </cfgrid>
<cfset AjaxOnLoad("init")>

my js:
<script language="JavaScript" type="text/javascript">
dataValidator = function(editEvent){
	if (editEvent.field == "Kat_ID"){

         if (isNaN(editEvent.value)){
            alert("Please enter a numeric value in this field.");
            editEvent.cancel = true;
         }
      }
   }
   addValidator = function(){
      mygrid = ColdFusion.Grid.getGridObject('Kategoriegrid');

      mygrid.on('validateedit',dataValidator);
   }
   init = function(){
      addValidator();
   }
</script>

Open in new window

0
Comment
Question by:Panos
  • 2
  • 2
  • 2
8 Comments
 
LVL 28

Accepted Solution

by:
Pravin Asar earned 250 total points
ID: 33734367
Have you tried using type="numeric"?

This one does validation.


<cfgridcolumn name="v1"  type="numeric" >
0
 
LVL 28

Expert Comment

by:Pravin Asar
ID: 33734486
data validators do not check the required fields, max length , etc.

These you need to implement at clientside (Javascript) and at serverside too.
0
 
LVL 2

Author Comment

by:Panos
ID: 33734661
Hi pravinasar.
Can you help me with the clientside (javascript) validation.I usually use jquery validation for form fields,but how is this working with the gridcolumns:
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 14

Assisted Solution

by:Scott Bennett
Scott Bennett earned 250 total points
ID: 33761129
To add more validators you edit the javascript where the validation occurs. In my example that you are referring to in your URL, I put a validator for a numeric field. You can make more validators by creating a condition for each field you want to check, then validating the data for each of the different data types. Here are some examples (untested code) of how you might check for a string field to make sure it is not blank and it is not too long.
if (editEvent.field == "KAT_ID"){

         if (isNaN(editEvent.value)){
            alert("Please enter a numeric value in this field.");
            editEvent.cancel = true;
         }
}
if (editEvent.field == "KAT_TEXT"){
         //Check if field is blank
         if (editEvent.value == ""){
            alert("Please enter a value in this field.");
            editEvent.cancel = true;
         }
         //Check if field is too long
         if (editEvent.value.length > 100){
            alert("Please enter a value that is less then 100 characters.");
            editEvent.cancel = true;
         }
}

Open in new window

0
 
LVL 14

Assisted Solution

by:Scott Bennett
Scott Bennett earned 250 total points
ID: 33761146
For additional reference, here is the original post that the Ajaxian article you are referencing was based on: http://www.coldfusionguy.com/ColdFusion/blog/index.cfm/2007/11/28/CF8-AJAX-Features-Validating-CFGrid-Data
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 33763496
thank you for your help
regards
panos
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now