Author Topic: validations:  (Read 3318 times)

elearnster

  • Pro Economy
  • Newbie
  • *
  • Posts: 20
    • View Profile
validations:
« on: July 29, 2014, 10:12:29 pm »
I am a new user and can not get validation to work.  Below is a sample program.  Could you identify what I am missing?

<!--jQuery dependencies-->
<html>
<head>
 <meta charset="utf-8">
 <!--jQuery dependencies-->
   <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/base/jquery-ui.css" />   
   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
   <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>

<!--PQ Grid files-->
    <link rel="stylesheet" href="pqgrid.min.css" />
    <script src="pqgrid.min.js"></script>

   
<!--jqueryui touch punch for touch devices-->
    <script src="touch-punch/touch-punch.min.js"></script>

<!--PQ Grid Office theme-->
    <link rel="stylesheet" href="themes/office/pqgrid.css" />
 
</head>

<body>    

    <h2>Selecting the Best Year Worksheet</h2>
   <div id="grid_custom_editing"></div>
   
<script>

   $(function(){
   
    var arrayData =    [
      {year: '2009', ab: 500, hits: 100, hr: 20, so: 50, bb: 50, avg: ".200"},
      {year: '2010', ab: 500, hits: 100, hr: 20, so: 50, bb: 50, avg: ".205"},
      {year: '2011', ab: 500, hits: 100, hr: 20, so: 50, bb: 50, avg: ".220"},
      {year: '2012', ab: 575, hits: 127, hr: 20, so: 50, bb: 55, avg: ".231"},
      {year: '2013', ab: 575, hits: 127, hr: 20, so: 50, bb: 55, avg: ".240"}
   ];
   
   var obj = {   
      title: "Players Name",
      width: 743,
      height: 222,
      width: "auto",
      dataModel: {
         data:arrayData,
         location: "local"
      },
      scrollModel: { horizontal: false },
      bottomVisible: true,
      numberCell: false,
      columnBorders: true,
      selectionModel: { type: 'cell' },
      hoverMode: 'cell',
      scrollModel: { autoFit: true },
      highlightText: { on: true },
      collapsible: false,
      track: true,
      editor: { type: 'textbox', select: true, style: 'outline:none;' },
      validation: { icon: 'ui-icon-info' },
      editModel: {
            saveKey: $.ui.keyCode.ENTER,
            keyUpDown: true,
            cellBorderWidth: 0,
            onBlur: 'validate'
        },   

      colModel: [
         {title:"Year", width:60, dataType:"string", align:"center", editable: false, resizable: false, sortable:false, dataIndx: "year"},
         {title:"AB", width:60, dataType:"integer", align:"center", editable: false, resizable: false, sortable:false, dataIndx: "ab"},
         {title:"Hits", width:60, dataType:"integer", align:"center", editable: false, resizable: false, sortable:false, dataIndx: "hits" },
         {title:"HR", width:60, dataType:"integer", align:"center", editable: false, resizable: false, sortable:false, dataIndx: "hr"},
         {title:"BB", width:60, dataType:"integer", align:"center", editable: false, resizable: false, sortable:false, dataIndx: "bb"},
         {title:"SO", width:60, dataType:"integer", align:"center", editable: false, resizable: false, sortable:false, dataIndx: "so"},
         {title:"AVG.", width:60, dataType: "float", align:"center",resizable: false, sortable:false, dataIndx: "avg",
            validations: [   { type: 'gt', value: 1, msg: "Error" }] }         
      ]
   };
   
    var $grid = $("#grid_custom_editing").pqGrid(obj);
   
   //Do validations in cellBeforeSave event
    grid.on("pqgridcellbeforesave", function (evt, ui) {
        var isValid = grid.pqGrid("isValid", ui).valid;
        if (!isValid) {
            grid.find(".pq-editor-focus").css({ "border-color": "red" });
            return false;
        }
    });   

 }); 
 
</script>   

</body>
</html>

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: validations:
« Reply #1 on: July 29, 2014, 10:50:51 pm »
variables names should match.

you have initialized the pqgrid with a variable name of $grid while you use variable name of grid at other places.

Alternatively in events the grid instance can also be accessed as $(this)

elearnster

  • Pro Economy
  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: validations:
« Reply #2 on: July 30, 2014, 06:19:59 am »
Thank you.  It works as advertised.