Tuesday, April 06, 2004

It is important to remember that the InfoPath object model is focused on the manipulation of data within an XML DOM. The majority of coding that I do within forms tends to be centralized within the OnAfterChange event. This is the last event that fires on a field. This event actually fires twice. What happens is the first time the event fires, the node object is removed (DELETE) from the XML DOM and the second time the new value is added (INSERT). It is always important to remember when writing your code to be aware of which event is firing.

 

For example, to see the node operations create a field called AddedExpense and place the following code within the OnAfterChange event.

 

function msoxd_my_AddedExpense::OnAfterChange(eventObj)

{

// Write code here to restore the global state.

 

            if (eventObj.IsUndoRedo)

                        {

                                    // An undo or redo operation has occurred and the DOM is read-only.

                                    return;

                        }

            // code added below

            XDocument.UI.Alert(eventObj.Operation);

}

 

The first time you will be prompted with a “DELETE” and the second time with an “INSERT” message.

 

This becomes important if you are recalculating the fields and expect to find the new value that the user has just entered. If you are not careful you may actually get the old value or a blank value.


1:01:52 PM