Solved

cfgridcolumn validation

Posted on 2010-09-21
8
1,341 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 14

Assisted Solution

by:SBennett
SBennett 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:SBennett
SBennett 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

760 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

19 Experts available now in Live!

Get 1:1 Help Now