Range of numbers in dropdown based on variable

Let’s say I have a variable:

NumProducts = 4

Is it possible to have a dropdown list populated so that you get:

Number pf products
0
1
2
3
4

Then, if I decrease NumProducts to 3 I get:

Number of products
0
1
2
3

If possible, I want to avoid DPs with lots of states as there could be quite a few permutations in this particular prototype.

Hopefully that makes sense!

Cheers
Andy

Hi!

You could do this quite easily with a repeater.

In the repeater’s dataset, put as many rows as you want to accommodate in your dropdown. You can go way over: add 20 if you like, even if you never plan on showing more than 10.

You can just use the default Column0 column that the repeater comes with, and it doesn’t matter at all what the column contains. It just matters how many rows are in the dataset. (A repeater won’t display more rows than what is contained in the dataset.)

Place the label widget that will show the number in the repeater row, and in the event On Item Loaded, place the following code:

On Item Loaded
  Set text of (number label) to value [[Item.index - 1]] 

Item.index gives you the current row number of the repeater. The minus 1 is there because Item.index starts at one, not zero, and you want it to start at 0.

Then, you just need to filter the repeater to make it show the number of rows specified by your NumProducts variable when you change that variable. Pseudocode below

On Whichever Event
  Set variable NumProducts to 10
  Add filter rule [[Item.index <= NumProducts + 1]] to repeater remove other filters

To get the clicked value, add this to the label widget (inside of the repeater)

On Clicked or Tapped (of label widget)
  Set text on (whatever) to text on This widget.
1 Like

I think I get that. I was heading in the repeater direction in my head but wondered if there was another way. So, the dropdown would have to be created using a dynamic panel or something rather than using an actual dropdown? Is that what you’re saying?

Ok, I’ve got some of that working. The issue I have is filtering. I have a repeater with 7 rows I’ve tried:

[[Item.index < 5]]

And, as per the tutorial:

[[Item.Column0 < 5]]

Just sticking to a fixed number for simplicity

But it still displays all 7 rows when I apply the filter. Column0 just has the numbers 1 to 7.

Ok, just added a button to do the filter and that works. But what I want is to click on a row in the repeater to apply the filter. I can’t fathomy why that doesn’t work. So I double click on the repeater and add the filter there. If I copy and paste the same filter interaction onto a button then it does work.