0

I'm using jqGrid plugin and I want to add onKeyPress event to each field of edit form.

This code works for IE8, but fails in FF and IE7

 {name: 'name', index: 'name', width: 200, editable: true, 
     sortable: false, search: true, editoptions: { readonly: false, size: 32, 
     'onKeyPress': 'if($("#cbLanguage").attr("checked"))togeo();' }, 
     editrules: { required: true }}

How to modify this to make it work in IE7 and FF? Thanks.

5
  • Do you get any error? can you put in a console.log inside the function to see if it gets called. Have you got a demo url? Commented Aug 3, 2009 at 11:32
  • I don't get any error. And sadly no url. I'm testing it on local machine. Commented Aug 3, 2009 at 11:36
  • well try the console.log or a debugger statement inside the KeyUp function to see if it event gets called. Can you use firebug to see if the event gets added to the input box also Commented Aug 3, 2009 at 11:37
  • you could also use a $('input.editClass').live('keyup' func). If you then add a class to the input when it is in edit mode the keyup event will bubble to the live handler and run your function Commented Aug 3, 2009 at 11:40
  • I tested it. and onkeypress event is never fired. Commented Aug 3, 2009 at 12:05

2 Answers 2

2

Found the solution! In order to assign event to field I need to add following to editoptions:

dataEvents:[{type:'keypress', fn: function(e) {
if($("#cbLanguage").attr("checked"))togeo(); }}]
Sign up to request clarification or add additional context in comments.

Comments

1

Kudos to karim79 for spotting the event issue.

In addition You will be better of using a function rather than an implied string as a function. Easy to read/maintain.

name: 'name', index: 'name', width: 200, editable: true, 
     sortable: false, search: true, editoptions: { readonly: false, size: 32, 
     'onKeyUp': keyUpFn }, 
     editrules: { required: true }}



function keyUpFn (){

 $("#cbLanguage").is(':checked') ){
   togeo();
 }

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.