Reputation: 14702
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.
Upvotes: 0
Views: 6738
Reputation: 14702
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(); }}]
Upvotes: 2
Reputation: 78667
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();
}
}
Upvotes: 1