Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1405
  • Last Modified:

cfgridcolumn validation

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
Panos
Asked:
Panos
  • 2
  • 2
  • 2
3 Solutions
 
Pravin AsarCommented:
Have you tried using type="numeric"?

This one does validation.


<cfgridcolumn name="v1"  type="numeric" >
0
 
Pravin AsarCommented:
data validators do not check the required fields, max length , etc.

These you need to implement at clientside (Javascript) and at serverside too.
0
 
PanosAuthor Commented:
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
Independent Software Vendors: 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!

 
Scott BennettCommented:
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
 
Scott BennettCommented:
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
 
PanosAuthor Commented:
thank you for your help
regards
panos
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now