Iterating though an array

You can then reverse the condition with !:

SELECT(pageVars.DropDownArray, !IS_IN_ARRAY(pageVars.testSelected, item.Country))

I had exactly the same thought at the same time!!! - It works, but as always - creates another crazy problem! hey ho!

So… I want people to rank a list of things. Each rank is unique and each thing can only have one rank. Dropdowns seemed like the obvious choice, but once ranked, if I remove that thing from the list of things to be ranked, it instantly stops being rankable and thus disappears from the rank I’ve just given it!


Right, now I think I get what you’re looking for. :slight_smile: Always good to give the whole problem so we can solve the right thing.

Essentially, you need four concepts:

  • allOptions: array containing all options, say 1, 2, 3.
  • selectedOptions: array containing each selected option
  • availableOptions: array containing options that are still available
  • items: array of objects to make choices for; let’s say they have schema {id: 0, name: "Banana", selectedOption: null}.

Now, we can infer selectedOptions and availableOptions from just allOptions and items with formulas:

  • selectedOptions: SELECT<option>(MAP(items, item.selectedOption), !IS_EMPTY(option))
  • availableOptions: SELECT(allOptions, !IS_IN_ARRAY(item, selectedOptions))

Now you can either maintain these in pageVars.selectedOptions and pageVars.availableOptions and e.g. setting them via page variable onchange listeners so they are always up to date, or just copypaste the first formula into the second one. This kind of aliasing is getting improvements in the future.

Then, it’s just a matter of binding the dropdowns to availableOptions, and when a selection is made, setting that item’s selectedOption to the selected value via

MAP(items, IF( ==, SET_KEY(item, "selectedOption", outputs["Dropdown"].selection.value), item))

(the actual output will be different based on the flow function you use, and items will need to be replaced with e.g. the page variable your items are stored in)

Amazing -It’ll take me a little while to work my way though those concepts - but one thing leaps out at me - what does the “<option>” do in the SELECT function.

A more basic question - where can I go to find more basic instructions of what the formulas do - are they akin to Javascript or something else?

It lets you define a different name than the default item for the item under iterarion, so you can nest multiple functions where it would otherwise be unclear whst item refers to.

They do work like JavaScript, but also like functions in any programming language — take an input and produce a deterministic output (with few exceptions like the ones generating random values). The docs reference for formula functions is all there is now, hope to write more tutorials/guides soon.

1 Like

I have always wondered how to nest functions - so that’s amazing - thank you.

1 Like