Checkboxes with variable number of options

I currently have a checkbox UI that allows the user to pick multiple dates nearby a given (variable) date. The checkboxes have Data that looks like this:
dates0
plus some computation to find the date of the next two days (for a total of exactly 3 checkbox items).

My problem: what I actually want is not always exactly 3 dates to pick from, but instead a variable number of checkboxes, between two variable dates. I want to start at date#1, and then have a checkbox for each subsequent day, until I get to date#2. (Let’s say there will be between 1 and 5 days in that date range.)

Is there any way to make a checkbox picker, with a computed and variable number of checkbox items?

Hi @dongeddis, it sounds like you want to have a checkbox list automatically populated with dates in between a start and end date.

Lets say i have a startDate that looks like this:

{
  "day": 25,
  "month": 7,
  "year": 2022
}

and an endDate that looks like this:

{
  "day": 30,
  "month": 7,
  "year": 2022
}

Given these two dates, you would need an list/array of dates to be put into the data property of the checkbox list. You can use this query expression:

FROM
  offset
IN
  RANGE(0, DAYS(startDate, endDate))
SELECT
  ADD_TO_DATE(startDate, offset, "days")

This would output the results that would look like this:

[
  {
    "day": 25,
    "month": 7,
    "year": 2022
  },
  {
    "day": 26,
    "month": 7,
    "year": 2022
  },
  {
    "day": 27,
    "month": 7,
    "year": 2022
  },
  {
    "day": 28,
    "month": 7,
    "year": 2022
  },
  {
    "day": 29,
    "month": 7,
    "year": 2022
  }
]

With this, you can set a variable on an action or run it through a data flow using two date pickers to populate the checkbox list.

image

Thank you @joechrz for the assist!

1 Like

OMG! That was totally awesome! A great solution to my specific problem, and it also teaches me new tricks that I might use in other contexts. Very much appreciated. Just implemented in my app, and it works great!

(The one change I made: do a FORMAT_DATE(…,“MM/DD/yyyy”) in the SELECT around ADD_TO_DATE.)

1 Like