Solved

cfgridcolumn validation

Posted on 2010-09-21
8
1,370 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
8 Comments
 
LVL 29

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 29

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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

734 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