Cancel the Operation for an Event

Because the components inherit the CancelableEvents class, you can direct an extension to cancel the operation associated with an event by throwing an error or returning a rejected Deferred promise. Subscribe to the event. When the event occurs, cancel the operation for the event.

The following code example shows how to cancel an operation in the PDP by throwing an error if a product option is selected and someCondition is true:

          pdp_component.on('beforeOptionSelection', function()    {
  if(someCondition)
    throw new Error('Canceling the select option operation.');
}); 

        

The following code example shows how to cancel an operation in the PDP by returning a rejected promise if a product option is selected and someCondition is true:

          pdp_component.on('beforeOptionSelection', function()    {
  if(someCondition)
    return jQuery.Deferred().reject(new Error('Canceling the select option operation.'));
}); 

        
Note:

If you cancel the operation associated with an event, the after event does not occur.

Related Topics

Work with Events in an Extension
Subscribe to Events

General Notices