Event Author API

add:widget

Fires when an author clicks on the "Add new" button on the Item edit page.

You would want to be notified about this event firing, because you might want to enforce a maximum number of widgets in a particular column of the Item before more can be added, for example.

Use event.preventDefault() to block adding widgets and prevent unexpected behavior.

Examples

// Standard usage to listen to the add:widget event
authorApp.on('add:widget', function (event) {
    console.log('This code executes when the author clicks on the "Add new" button.');
    console.log(event.data);
    console.log(event);
});

// Example to prevent adding more widgets
authorApp.on('add:widget', function (event) {
    if (shouldNotAddMoreWidgets) {
        event.preventDefault();
    }
});

Callback arguments

The event callback function will be called with an AuthorEvent instance as an argument (unless indicated otherwise). The AuthorEvent object provides further information for the event that has been fired. Additional data attributes listed below can be accessed from the event.data object. The AuthorEvent object will look like the example below:

authorApp.on('[name of the fired event]', function (event) {
    console.log(event);
    /*
        {
            "name": "[name of the fired event]",
            "data": {
                // additional data attributes
            }
        }
    */
});
  • region_id string
    The ID of the column in the user interface of the Item editor where the widget has been added.
Was this article helpful?