save - Events - Author API

Author API Events

save

Fires before an Item is to be saved.

You would want to be notified about this event firing, because you might want to display your own custom save dialog or you might want to run additional validation on the current Item before saving, for example.

When the event has been fired, you can use event.preventDefault() to prevent the Item from being saved. If the save event is fired when editing a Question or Feature, the preventDefault function accepts an optional boolean argument discardWidgetChanges. If set to true, the modifications of the Question/Feature are discarded. The default value for discardWidgetChanges is false.

Examples

// Standard usage
authorApp.on('save', function () {
    console.log('This code executes before an Item is to be saved.');
});

// Prevent the save operation and discard changes
authorApp.on('save', function (event) {
    if (shouldNotSave) {
        event.preventDefault({ discardWidgetChanges: true });
    }
});

Callback arguments

  • itemJson object

    JSON of the Item to be saved.

Related articles

  • The save() method, which saves the current Item being edited.
  • The save:error event, which fires when an Item has failed to save.
  • The save:success event, which fires when an Item has successfully saved.
Was this article helpful?

Did you arrive here by accident? If so, learn more about Learnosity.