1

I want to restrict the user in toolbar search by not allowing him/her using Some Special Characters like ('/','>','<','|').Please help me out.

$("#tblFundComp").bind("keydown",function(e) 
{
  if(e.keyCode >=48 && e.keyCode <=57 ) 
  { 
    return false; 
  }
  else 
  { 
    return true; 
  }
}); 

I have placed this piece of code after before search function. But this does not work

Oleg
  • 220,925
  • 34
  • 403
  • 798
hkv
  • 163
  • 1
  • 6
  • 15

1 Answers1

0

If you want allow only some special characters are entered in the input field of the search toolbar you can use dataEvents of the searchoptions defined using type:'keypress' or type:'keydown'. It will follows to call jQuery.bind and jQuery.unbind for the corresponding input field. The code fragment which allows only digits is following

searchoptions: {
    dataEvents: [
        {
            type: 'keypress', // keydown
            fn: function(e) {
                // console.log('keypress');
                if(e.keyCode >=48 && e.keyCode <=57) {
                    // allow digits
                    return true;
                } else {
                    // disallow the key
                    return false;
                }
            }
        }
    ]
}

In the live demo you will be not able to enter digits in the search field for the 'Name'.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @ Oleg: Wow thats awesome stuff... As you said i did placed my code in some other place which was causing problem and any ways thanks a lot – hkv Nov 17 '10 at 05:17
  • @ Oleg: One more small help i wanna create the context menu which is dynamic in nature which will arise as soon as you rightclick the row. can u please suggest me how this can be done.I have placed my question in the following URL http://stackoverflow.com/questions/4202200/context-menu-in-jqgrid-on-row-click-in-jqgrid – hkv Nov 17 '10 at 07:07