Forum Academy Marketplace Showcase Pricing Features

Custom Plugin: Publish State using App Type

I am building a custom plugin that needs to expose an object on a custom element state. When the element is added to the page, the user sets a field indicating the data type. The element then exposes the new data generated on a state field defined as that type.

As an example, let’s say I have a Contact type defined in my application with fields First Name and Last Name.

image

As per the data API on data formatting, I am sort of expecting that the data object for this type would look like this:

{
“First Name”: “Chris”,
“Last Name”: “Beckett”
}

Here is the code in my custom plugin initialize where I register a message handler to receive the data and then try to publish it to the state field.

function(instance, context) {
window.addEventListener(‘message’, (event) => {
instance.publishState(‘data’, event.data);
instance.publishState(‘origin’, event.origin);
instance.triggerEvent(‘message’);
});
}

I have debugged the code and the event is being fired, and the event.data is formatted correctly as noted above. The origin state is being updated correctly. The data state is not.

What is the object supposed to look like to publish state defined as a Bubble type?

I submitted this as a support request to Bubble. Here is a response from the support team. I guess at this time, it is not possible to create App Type objects from a plugin.

Because Bubble objects aren’t JSON and can’t be interpreted from JSON, it is impossible to create new things in a plugin. At this time, only the app can create new things. You can, however, change fields in a thing passed into a plugin. You might consider restructuring so that user passes the thing in and then plugin changes fields on the thing.

You may find this helpful

1 Like