Hi,
I am studying, from time to time, how to develop plugins for Bubble.
As per the Bubble plugin building documentation, in the update function, i.e. the function that is called whenever an element field or field value change, one can pass 3 objects as parameters:
- the instance object (that represents the element itself);
- the context object (an object containing “some Bubble utilities” as, for example, a function to get some of the current user data type fields);
- the properties object (an object that contains all the field values of the fields have been created in the field section of the element tab).
As I am willing to better understand the “mechanics” of plugin development, and in particular when the functions initialize and update are triggered (to me it’s a little obscure that documentation sentence about the update function: “update: this is called whenever a field or a field value changes”), I have written some essential code that alert objects content.
In particular, willing to understand how to access the field values of the declared fields, I have created a field, called “centerLocation” set as a “Dynamic value” (note, I am trying to make a custom Google Maps plugin) and, after having set its value in the Bubble editor to a specific location (geographic address), I want to alert it.
In the Bubble editor, I have set it to my city:
and then I have tried to show this address in an alert by accessing to the properties object in the update function…
But when I launch the preview, I get the following js error:
So, in order to investigate, I have tried to alert the properties object content:
and, with my surprise, this is what I get:
i.e., it seems the properties object actually contains “current user” and “keys” objects, which instead should be contained, as per the documentation, in the context object.
Instead, if I alert the context object, still with a certain surprise, I get:
i.e. exactly what I expected to find in the properties object.
As a proof, if I alert “context.centerLocation.address”
this time I “correctly” get the address I set in the centerLocation field in the Bubble editor:
Now, in order to study how to buld plugin, beside relying on the official documentation, I am also watching other plugin codes. These ones anyway seem to access field values as stated by the documentation, i.e. I have not found in their code the same behaviour as in my mini-test.
So I would like to ask, does anyone know why I am experience what seems a weird behaviour? Am I doing something wrong or is there something wrong in the Bubble documentation?
Thank you!