Listening to SubForm Element Events
This article is for advanced users with Javascript experience.
The code snippet below shows how to the 'add' event generated by the SubForm element. These events are generated when the SubForm window is closed. Each event returns a reference to the SubForm class and to the record being added/updated.
form.getFieldByName('SubForm').subFormInst.eventMgr.addListener('add',function(inst,record){ // do something here },form)
Replace 'SubForm' in the code above with the name of your field. It is case-sensitive.
Event | Details |
---|---|
add(inst,record) | Called after a row is added. |
update(inst,record) | Called after a row is updated |
beforedelete(inst,record) | Called before a row is deleted, return false to abort the delete or true to continue |
Adding Listeners on Form Load Events (via Form Actions)
When attempting to add a listener to a SubForm element, via a form action (on load), the subForm instances may not be ready. The code example below shows how to listen for both the add an update events and also add a 2 second delay before attaching the listeners
// This function will receive the field and form objects. function(field,form){ // I get called from the add/update event. var handleEvent = function(inst,record){ // do event processing here } var setupListeners = function(form){ // listen to the subform add form.getFieldByName('SubForm').subFormInst.eventMgr.addListener('add',handleEvent,form) // listen to the subform update events form.getFieldByName('SubForm').subFormInst.eventMgr.addListener('update',handleEvent,form) } // call after 2 second delay setTimeout(setupListeners.createDelegate(form,[form]), 2000); }
0 Comments