Solved

cfgridcolumn validation

Posted on 2010-09-21
8
1,354 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ebay api to see some data about my customers 2 30
How can i  prevent default  Submision? 6 27
Grunt script for Build Process 1 29
QQ problem 22 23
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

809 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