Why is "instance.data.variable_name" undefined when called inside the initialize function?

I am creating a plugin, and I have added a dynamic text field named input_id_box. It has a default value of PhoneInput.

But when I use that variable inside the initialize function it returns undefined.

For example:

function(instance, context) {
    var input = document.querySelector("#" + instance.data.input_id_box);


This will console log undefined, but I was expecting it to log the default value of PhoneInput.

Why is it doing this?

And how do I get access to the input_id_box field data when initializing the plugin?

Thanks, that has fixed it, although I’m not sure why…

Regarding the update function bubble says “this is called whenever a field or field value changes.”

When the plugin first loads on the page no fields or field values have changed, it is merely initialized. So why does moving my code to the update function work?

Also, I’m not sure what you mean by “If you want to use data it’s for sharing variables between the functions”? Can you also elaborate on that?

Sorry for the pedantic follow up questions - just trying to better understand :slight_smile:

1 Like

In what circumstance would my code go in the initialize function?

Now I don’t understand why that exists.