Plugin help "Current Option"

I’ve been creating a few plugins for my site and could use some help on one of them.

I would like to expose the “current option” field available on items like dropdown lists to my plugin. This will be used for iterating rows of data and instead of having to have a defined list of input fields like Field 1-10 the potential user (or myself) of this plugin create an indefinite list of fields by comma separating the “current option” fields easily in the bubble editor.

Right now I have:

  1. An exposed a state called “Current Option”
  2. A field to grab the App-Type and another field to get the data source
  3. A field named “Input Value” where I expect the user to build a comma separated list of the fields from the “Current Option”. It has to refer to itself and then “current option” instead of just a simple “current option” field, but hey, I can input it using standard bubble fields the way I want…

The input ends up looking like this:
image

In my code I’m doing something like this now:

var myData = properties.input_source.get(0,10);

var myRow;

for (var i=0;i<myData.length();i++){

 myRow = myData[i];
 instance.publishState("current_option",myRow);

 // This is where I want to push that state out and consume the values from the "current option" (that I just set)
 // Assume these fields are {"field1":"Demo","field2":"Test"}
 alert(properties.input_value); //This should show something like "Demo,Test" in the alert box

}

Problem is - seems as though the publishState function doesn’t commit that State until the whole code finishes running (therefore it doesn’t work inside of a loop).

Another side effect of that is that I can’t expose a state “percentage complete” and use that as a data source for a progress bar because the state won’t actually be pushed until the entire code is complete.

There is probably a way to do this I’m missing (or over thinking it), but the documentation isn’t all that great so I’m having to do a lot of trial and error to get it to work.

Any help would be greatly appreciated!

Thanks,
Chris

Hi Chris,

The issue is twofold: the code is running synchronously, and potentially gets rerun from the start to retrieve more data.

You might get the current progress to publish if you run that asynchronously to the loop.