ProjectDocument.removeHandlerAsync method (JavaScript API for Office v1.1)

JavaScript API for Office v1.1

Asynchronously removes an event handler for the task selection changed event in a ProjectDocument object.

Last modified: June 12, 2014

Office.context.document.removeHandlerAsync(eventType [,options], callback);

eventType

Type: EventType

Specifies the type of event to remove. Required.

For an event in a ProjectDocument object, the eventType parameter can be Office.EventType.TaskSelectionChanged, or the corresponding text value of the enumeration. TaskSelectionChanged is the only event type that Project 2013 supports.

options

Type: object

Specifies the following optional parameters.

handler

Type: object

The event handler function to remove. Optional.

asyncContext

Type: array, boolean, null, number, object, string, or undefined

A user-defined item of any type that is returned in the AsyncResult object without being altered. Optional.

callback

Type: object

A function that is invoked when the callback returns, where the only parameter is of type AsyncResult. Optional.

When the function that you pass to the callback parameter executes, it receives an AsyncResult object that you can access from the callback function. For the removeHandlerAsync method, the AsyncResult.value property always returns undefined. To determine the success or failure of the operation, use the AsyncResult.status property. If the operation fails, use the AsyncResult.error property to access an Error object that provides information about the error.

The Project-15.js file adds the removeHandlerAsync method to the ProjectDocument object and adds the TaskSelectionChanged constant to the Office.EventType object.

In the following example, the addTaskEventHandler function calls the manageEventHandlerAsync function to add the onTaskSelectionChanged event handler for the Office.EventType.TaskSelectionChanged event. Similarly, the removeTaskEventHandler function calls manageEventHandlerAsync to remove the event handler.

In the following code, the textBox object is a reference to a textarea control in an HTML file, for example: <textarea id="textBox" rows="6" cols="25"></textarea>

var _projDoc;

// The initialize function is required for all apps.
Office.initialize = function (reason) {
    // Checks for the DOM to load using the jQuery ready function.
    $(document).ready(function () {
    // After the DOM is loaded, app-specific code can run.
    _projDoc = Office.context.document;
    });
}

// Task selection changed event handler.
function onTaskSelectionChanged(eventArgs) {
    textBox.value = "In task selection change event handler";
}

// Add or remove the specified event handler.
function manageEventHandlerAsync(eventType, handler, operation) {
    _projDoc[operation]   //The operation is addHandlerAsync or removeHandlerAsync.
    (
        eventType,
        { handler: handler },
        function (asyncResult) {
            var message = "Operation: " + operation;
            message = message + "\nStatus: " + asyncResult.status + "\n";
            textBox.value = message;
        }
    );
}

// Add a task selection changed event handler.
function addTaskEventHandler() {
    manageEventHandlerAsync(
        Office.EventType.TaskSelectionChanged,  // The task selection changed event.
        onTaskSelectionChanged,   // The event handler.
        'addHandlerAsync'         // The method to add an event handler.
    );
}

// Remove a task selection changed event handler.
function removeTaskEventHandler() {
    manageEventHandlerAsync(
        Office.EventType.TaskSelectionChanged, 
        onTaskSelectionChanged, 
        'removeHandlerAsync'      // The method to remove an event handler.
    );
}

For a code example that shows how to use a TaskSelectionChanged event handler in a Project app, see How to: Create your first task pane app for Project 2013 by using a text editor.

Supported clients

Project Standard 2013, Project Professional 2013, PowerPoint 2013 SP1, PowerPoint 2013 RT

Libraries

Office.js, Project-15.js

Namespace

Office

Show:
© 2014 Microsoft