Event API
Infinite Options' Event API allows developers to tie in to and react to different processes that occur within Infinite Options. This article contains information on how to subscribe to certain actions, as well some context on what you can do with these events.
Note: This includes technical information. Knowledge of the JavaScript language is required.
Subscribing to events
Events are subscribed to by calling the subscribe method before the app has ran. The subscribe method takes two arguments, a string matching the name of the event (events are listed below), and a callback function that takes a single argument, event. In order to access this method, you will need to tie into the beforeReady callback. Here's an example of this:
<script>
// Create "window.Shoppad.apps.infiniteoptions" object if it doesn't already exist
"Shoppad.apps.infiniteoptions".split(".").reduce(function(o, x) { if (!o[x]) {o[x] ={};} return o[x] }, window);
// Define beforeReady callback
window.Shoppad.apps.infiniteoptions.beforeReady = function(subscribe) {
subscribe('appLoad', function(event) {
console.log('appLoad', event);
});
};
</script>Note: You will need to define the beforeReady callback before the app has loaded. If you are explicitly loading the script using the instructions found in this article, you will need to define the callback before that script is called. If you aren't explicitly loading the app, defining the callback anywhere in the <head /> will suffice.
Events
Here's a list of all the available events.
appLoad
Fired when all fields have been added to the DOM and the app has run its initial processing.
fieldLoad
Fired every time a field is added to the DOM.
fieldChange
Fired every time a field is changed. To be specific, this is fired when the native change event is fired for select menus, checkboxes, radio button, and when the keyup / touchend event is fired for text areas, text inputs, and number inputs.
productBundleAdd
Fired when a product bundle is selected (can occur on page load).
productBundleRemove
Fired when a product bundle is unselected (can occur on page load).
fieldShow
Fired every time a field is shown.
fieldHide
Fired every time a field is hidden (can occur on page load).
productBundleCartSubmit
Fired when product bundles are attached and the user submits the main product's cart.
Note: This event is cancelable. Call event.preventDefault(); to prevent the app from submitting the main product's form after product bundles have been submitted.
validationSuccess
Fired when validation for fields has passed.
validationFail
Fired when validation for fields has failed.
Note: This event is cancelable. Call event.preventDefault(); to prevent an alert with the error message from showing.
Last updated