When the user clicks on Edit in jqGrid, the form which opens has a few list boxes and text boxes. Depending on the value in a List box a couple of text boxes have to be disabled or set to read only when the form loads.
I got the piece working for the onChange event on the listbox to toggle the textboxes to disabled/enabled, but I am struggling to do it on the form load. I tried using the aftershowform, which already has a event handler, so I created another event say for example aftershowform2 and attached this event and the eventhandler fires. But the problem is the listboxes are dynamically loaded using an Ajax call (dataurl of editoptions) and aftershowform fires before these listboxes are populated with the options. Is there any different event which fires after the listboxes are loaded? The whole 开发者_JAVA百科application is framework driven, and it is hard to paste the code.
I see many ways which you can go to implement your requirements.
The first and the best one in my opinion would be the usage of dataEvents
of the editoptions with the type:'change'
(see this answer as an example). The corresponding code can be
editoptions: { dataUrl:...,
dataEvents: [
{
type: 'change',
fn: function(e) {
var v=$(e.target).val();
alert(v); // do something with selected item value
}
}
]
}
The binding to the functions defined by dataEvents
will be after the successful return of the select
contain from the server.
Another way would be modify your current implementation so that you replace jQuery.bind to jQuery.live (see a code template here).
精彩评论