I’m creating a plugin where I want to pass data from a field I created on the plugin to an exposed state on the plugin. In the Bubble app, I will set the field dynamically to text from my Bubble app. I created the field and state, as well as added this code to the update function in the plugin.
function(instance, context) {
let attempts = 0;
const maxRetries = 5;
function tryPublish() {
const preload = instance.data.preload_selection;
console.log(`update attempt ${attempts + 1}:`, preload);
if (preload && preload.length > 0) {
instance.publishState("selectionList", preload);
console.log("update: Published preload_selection to selectionList");
} else if (attempts < maxRetries) {
attempts++;
setTimeout(tryPublish, 200); // retry after 200ms
} else {
console.warn("update: Gave up after 5 tries");
}
}
tryPublish();
}
I’m using chatGPT to help with the code.
Unfortunately, the exposed state is empty in the Bubble app. When inspecting the element, the field shows the text, but the state is empty. Both the field and state are set to the same data type and the naming matches between the code and field/state settings in the plugin.
Where am I going wrong?