Tip: Use initial values with formula-driven drop-downs

Set initial values for formula-driven drop-downs using formulas that adapt to changing options.

For drop-downs with fixed values, you set the initial selection by choosing a value in Calcapp Creator. Simple and direct.

But when drop-down values are determined using a formula, those values aren’t known until the app runs. The drop-down in Creator is disabled because there’s nothing to select from yet.

Instead, you set the initial value using a formula. Select InitialValue from the property drop-down in the inspector:

The property selector, with InitialValue being selected

Example formulas

Select a specific value

If you know that 2 is always part of the available values, use this formula:

22

Select the first value

If you don’t know what values will be available and want the first one selected:

INDEX(Item.Values, 1)INDEX(Item,Values; 1)

The INDEX function selects the first value from Values. Item references the drop-down field that the InitialValue property belongs to.

Select the last value

INDEX(Item.Values, SIZE(Item.Values))INDEX(Item,Values; SIZE(Item,Values))

SIZE returns the number of values, which INDEX uses to select the last one.

Select the middle value

INDEX(Item.Values, SIZE(Item.Values) / 2)INDEX(Item,Values; SIZE(Item,Values) / 2)

Dynamic re-evaluation

Traditionally, a field’s InitialValue property is only read when navigating to the screen containing that field.

For formula-driven drop-downs, InitialValue is now re-evaluated whenever the available values change. This handles an important scenario: what happens when a user’s selection becomes invalid?

Consider two drop-downs: one for country, another for province. When the user changes countries, the province list updates. But if they had already selected a province, that selection likely becomes invalid since different countries rarely share province names.

Calcapp automatically re-evaluates InitialValue in this situation. If you’ve used a formula like INDEX(Item.Values, 1), the first province in the new list gets selected automatically, keeping the app in a valid state.

« Tip: Text-driven drop-down filtering Tip: Filter drop-downs with optional criteria »