Our upcoming release will introduce list fields: fields with drop-down menus.
There are two new options in the drop-down menu in the inspector, Number list and Text list. If your list solely consists of numbers, select the first option, otherwise select the second option. The List values section in the inspector enables you to add and remove values from your lists. Press the Add value button to add values and the button to remove them. Drag the symbol to reorder values.
You can select an initial value that is pre-selected for your user simply by selecting the option in the main app designer. If you don’t want an option to be pre-selected, select the first blank option. To enable your users to select a blank option, simply include an option under List values in the inspector with no content.
In the image above, a temperature conversion app is being built. You may recall that a temperature conversion app is currently available as an app template. That app uses a list panel asking users to select whether they want to convert degrees Celsius to degrees Fahrenheit or vice versa. With a list field as opposed to a list panel, users can make that selection without leaving the calculation panel.
The formula for the Result field might look like this:
As a text list is used, the value of the Conversion field must be compared to a text string, in this case “°C to °F.” The formula above converts the Input field to degrees Fahrenheit (from degrees Celsius) if that’s the conversion sought by the user and to degrees Celsius (from degrees Fahrenheit) otherwise.
Improving the formula
There are two changes we can make to the formula to improve the app. First, the Result field displays zero if no number is entered into the Input field. That’s because an empty number field is interpreted as zero. (An empty text field is interpreted as the empty string, or “”). To ensure that no result is displayed unless the user explicitly enters a number into the Input field, a formula like this one may be used (changes are marked):
The formula above wraps the original formula in an IF function. It simply states that if the Input field is blank, a blank value should be returned (courtesy of Calcapp’s custom BLANK function). Otherwise, the original formula is used to perform the conversion.
Finally, you may have noticed that there are no units specified in the app designer. With a field that always contains a weight in pounds, you can type “lbs” into the field in the app designer to ensure that values are formatted as, say, “10 lbs.” As the units used for the fields are not known until the user makes his or her selection, that system can’t be used.
There is a way around this limitation for the Result field, and it involves
changing it into a text field and making the units part of the formula. The
concatenation operator (“&”) enables you to join two text strings together (or a
number and a text string). This operator can be used to add “ °C” to the Result
field when the user converts the Input field to degrees Celsius and to add “ °F”
otherwise. In other words, we need
((9/5) * Input + 32) & "
((5/9) * (Input - 32)) & " °C".
Taken together, this is the resulting formula:
While this formula does the job, it’s too long to be easy to read. Splitting it up would have been ideal. That’s currently not possible, but Calcapp will soon enable you to make fields hidden. With hidden fields, we could add two such fields doing the temperature conversion and simply incorporate their values into the formula above, making it considerably simpler. Hidden fields will be explored in detail in a future blog post.