Additional field types
So far, we have covered number fields and date and time fields. Calcapp offers many more field types, including switch fields (which can be toggled to an “on” position or an “off” position), text drop-down fields, number drop-down fields as well as regular text fields. They are the topic of this guide.
To turn a field into a switch field, select Switch from the drop-down menu in the inspector (which reads Text in the image below). Switch fields can be used by users to toggle logical values (from TRUE to FALSE and back again).
Here’s an example of switch fields in use, including the preview sidebar which shows what switch fields look like in a finished app:
This simple app has three switch fields as well as a text field which displays one value when all fields have been toggled to the “on” position and another when at least one is in the “off” position. To do so, this formula is used:
To turn a field into a drop-down field, select Number drop-down or Text drop-down from the menu in the inspector. Drop-down fields enable users to select from a number of predetermined options (numbers or text strings).
The List values section in the inspector enables you to add and remove options. Press the Add value button to add options and the button to remove them. Drag the symbol to reorder options.
To make an option pre-selected when the field is first shown, select the corresponding option from the drop-down in the app designer (which reads °C to °F in the image above).
If you don’t want an option to be pre-selected, select the first blank option from the drop-down. To enable your users to select a blank option, include an option under List values in the inspector with no content.
To use different formulas depending on the value selected by the user, use the IF function. In the image above, the Result field might use this formula to determine if degrees Celsius should be converted to degrees Fahrenheit or the other way around:
To turn a field into a text field, click the abc button in the inspector. Text input fields enable users to enter text and text output fields enable you to display text using formulas.
Text fields can display multiple lines by toggling the Multiple lines property in the inspector. For input fields, this allows you to collect long-form answers (which can be emailed to you):
Using formulas to calculate text
Output text fields display text you “calculate” using formulas. This is particularly useful in conjunction with output text fields which display multiple lines. The most useful formula function to use with an output text field is IF, as you can then display certain text only if a condition holds.
There are many functions that handle text. Use the LEN function to determine the length of a text string and the LEFT, RIGHT and MID functions to return a new text string containing only part of another text string.
The LOWER and UPPER functions return a text string converted to only lower case or only upper case characters, respectively. Use the SUBSTITUTE function to substitute new text for old text in a text string. The FIND function searches for text strings in another text string and returns the position of the found text string. (If no text string is found, an error is returned, which you can determine using the ISERROR function.)
Text must be enclosed in quotation marks in formulas. If a literal
quotation mark should be part of a text string in a formula, type two
consecutive quotation marks (
Here is a sample app which gives an assessment of a given temperature:
The following formula is used in the image above:
This formula joins text strings together using the & operator and uses the IF formula function to select one of two text strings based on the temperature entered by the user. You can type NumberField1.FormattedValueNumberField1,FormattedValue to access a text string version of the number of the field, which has been formatted according to your instructions.
Validating text fields
Sometimes, you need to alert your users if they enter incorrect text in a text field. If you collect phone numbers or email addresses, for instance, you want to alert users to mistakes, such as a missing “@” symbol in an email address.
You may recall that validation can be used to ensure that numbers are within an interval you specify. For text fields, you need to associate a formula with the Valid property to do validation. Press the fx button next to the Valid property to edit the formula, which must evaluate to either TRUE or FALSE.
The function REGEXMATCH may be used for more advanced needs. To ensure that a text field contains a valid US phone number (like “(541) 754-3010”, “541.754.3010” or “541-754-3010”), use this formula:
The second parameter to REGEXMATCH is a regular expression, which can not only be used to validate text fields but also to extract and transform text. Our blog has a guide to regular expressions and Calcapp’s regular expression functions.
Here are two more useful regular expressions. To recognize a US Social Security number, use this formula:
To recognize an email address, use the ISEMAIL function (which uses a complex regular expression internally):
Continue reading about looking up values »