Unable to access data from Plugin Element's Fields

Hi all,

I’m very new to Bubble, and I’m attempting to build a plugin.

In my plugin, I’ve created an element, and I’ve defined a number of fields. Then in my Function initialize, I’m trying to access whatever is entered into the Fields via ‘instance.data.{fieldname}’. In my test app, I have the fields all filled in with the correct data type.

All the data from the fields return as undefined, and when I console.log the instance.data object, it is an empty hash.

What am I missing here? Do I need to use a workflow to make the values available in the backend?

Thank you in advance,

Daniel.

Hello @danielkellydev !

Properties are not available in initialize function, only on update !

You should prepare, in you initialize functions, functions for element modifications, and call this functions from your update function.

Think like that:
Initialize “prepares” the element, no matter what properties values you have.
Update changes your element depending on your properties values.

Initialize runs once at loading,
Update runs once a loading + everytime a property changes (for exemple, with a conditionnal, the background color changes on hover).

So you can’t use properties in you initialize function, and even if you can, you will have problems on properties change.

So for example:

in your initialize:

function(instance, context) {

    // create a function saved in your instance.data (instance.data is accessible from the update function)
     instance.data.changeColor = function(color){
            myelement.css('color', color);
     }
}

In you update:

function(instance, properties, context) {
      // call the function created in initialize with your field "color" value as entry
        instance.data.changeColor(properties.color);
}

Hope it’s helps !

Hi Thomas,

Thanks so much! That is immensely helpful, I’ll go ahead and implement this.