1

I'm trying to validate the search field for integer data alone but unfortunately am unable to do so. I have tried all possible solutions like searchrules:{required:true,integer=true} etc.. But none of them proves fruitful. I basically launch the search dialog with the field and without inputting any data, am hitting on the 'Find' button. As per the above options, i believe a validation message should be shown to the user asking him to enter a value in the field before hitting find.

[UPDATED] - Code Snippet

            var grid = $("#list");  
            grid.jqGrid({
             url:'/index.jsp',
             datatype: 'json',
             mtype: 'POST',
             colNames:['Name','Age', 'Address'],
             colModel :[ 
                  {name:'name', index:'name', width:55,search:true }, 
                  {name:'age', index:'age', 
                   width:90,editable:true,search:true, stype:'text',
                   searchrules:{required:true,integer:true}}, 
                  {name:'address', index:'address', width:80, 
                   align:'right', editable: true,search:false }
             ],
             pager: '#pager',
             jsonReader : {
                     root:"address",
                     page: "page",
                     total: "total",
                     records: "records",
                     repeatitems: false
             },
             rowNum:10,
             rowList:[10,20,30],
             sortname: 'name',
             sortorder: 'desc',
             viewrecords: true,
             gridview: true,
             autowidth: true,
             toppager: true,
             loadtext: "Loading records.....",
             caption: 'Test Grid',
             gridComplete: function(){ 

         }

          });

      **grid**.jqGrid('navGrid','#pager',
      {view:true,edit:true,add:true,del:true,refresh:true,
       refreshtext:'Refresh',addtext:'Add',
       edittext:'Edit',cloneToTop:true,
       edittitle: "Edit selected row"},
      {},{},{},
      {caption: "Search The Grid",Find: "Find Value",Reset: "Reset"},
      {});

[Updated] : Am not able to make the searchrules properly work for the single/advanced searching modes.

[Updated] : Even the 'Validation in Search' in jqGrid Demo is not working for searchrules.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Faz
  • 534
  • 1
  • 9
  • 27
  • You should post your code in the question – Sharun Apr 17 '13 at 05:46
  • Any help on this please? Am not able to make the **searchrules** properly work for the single/advanced searching modes. Any help is appreciated. Thanks! – Faz Apr 18 '13 at 12:21
  • Perhaps this [link](http://stackoverflow.com/questions/4074429/validation-before-submitting-the-search-form-generated-using-filtergrid-in-jqgri/4078683#4078683) will help you. – Sharun Apr 19 '13 at 06:29
  • Thanks slacker, I already gave it a try. In the above link, we will have to have our own custom validations established. But am just wondering as to why the default behavior of **searchrules** isn't working. Even the 'Validation in Search' in [link](http://www.trirand.com/blog/jqgrid/jqgrid.html) isn't working. Is this a reported bug? – Faz Apr 19 '13 at 12:04
  • @Faz: It seems me it's a bug in jqGrid. I'll post you my answer later (now I'm busy :-() – Oleg Apr 19 '13 at 13:20
  • I'm sure you will crack it down just like that.Thanks for this and please let me know if there is a workaround or permanent solution. – Faz Apr 19 '13 at 13:28
  • @Faz: I will post my detailed answer later, but the bug fix is [here](http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.4.5/js/jquery.jqGrid.src-ValidateSearch.js) – Oleg Apr 19 '13 at 14:19
  • Great!! Thanks!!! Please let me know where and what was the issue , when you find time later. – Faz Apr 19 '13 at 14:26
  • well,found the modified lines : 6079 & 6297. But not quite getting the actual reason for the changes ! – Faz Apr 19 '13 at 14:30

1 Answers1

0

The reason of described problem is a bug in jqGrid. The line

ret = $.jgrid.checkValues(val, -1, null, colModelItem.searchrules, colModelItem.label);

initialize the third parameter of $.jgrid.checkValues to null, but the last version of checkValues implementation started (see the line) with

var cm = g.p.colModel;

but g is initialized to null. The last modification which generates the error was based on my suggestion, but I don't wrote the part of the code.

One can solve the problem in different way. I would suggest to modify the line where $.jgrid.checkValues will be called with null parameter to the following

ret = $.jgrid.checkValues(val, -1, {p: {colModel: p.columns}}, colModelItem.searchrules, colModelItem.label);

Additionally, to be sure, I would suggest to modify one more line

if(!nm) { nm = g.p.colNames[valref]; }

to

if(!nm) { nm = g.p.colNames != null ? g.p.colNames[valref] : cm.label; }

The fixed version of jquery.jqGrid.src.js one can get here. I will post my bug report with the same suggestions later ti trirand.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks Oleg. Is there a possibility to get the minified version of the js file? I tried to convert it online but in vain. – Faz Apr 19 '13 at 20:31
  • @Faz: You are welcome! You can use [Microsoft Ajax Minifier](http://ajaxmin.codeplex.com/) for example: `AjaxMinifier.exe -enc:in utf-8 -clobber:true jquery.jqGrid.src.js -o jquery.jqGrid.min.js` – Oleg Apr 20 '13 at 09:10