Valid property

NumberField.Valid — Logical

Special value available in formulas:

Item

NumberField

The field this property is part of, enabling multiple checked items in the app designer to share the same formula and be updated all at once.

Consider the fields Field1 and Field2, which should only be considered to be valid if their values are greater than 4. Without using the Item value, the Valid property of Field1 would need to use the formula Field1 > 4Field1 > 4 and the Valid property of Field2 would need to use the formula Field2 > 4Field2 > 4.

Using Item, both formulas can read Item > 4Item > 4. This is useful if you have many fields and you want to be able to update their formulas all at once. To do so, click their check boxes in Calcapp Creator and make sure that a checked field is selected. Then, when you update a formula for one checked field, you update all the other checked fields too, which is a great timesaver.

Use Item in exactly the same way you'd use the regular name. Field1.VisibleField1,Visible and Item.VisibleItem,Visible are equivalent, for instance.

Whether the field is valid. The value of an invalid field is shown in red (unless a different warning color has been set). Below the field, a validation message is shown. Customize it through the ValidationMessage property.

To make a field required, use this property in conjunction with the NextScreenAvailable property of screens (preventing users from moving on to the next screen) and the Enabled property of buttons (preventing users from pressing a button). See below for more information.

Minimum and maximum values

A field is considered invalid when its Valid formula returns FALSE. However, you may not need to write a formula if your field only needs to be constrained in terms of minimum and maximum allowed values.

Set these values through the MinimumValue and MaximumValue properties. If a minimum value is set, the field is considered invalid if its value is less than the minimum value. Conversely, if a maximum value is set, the field is considered invalid if its value is greater than the maximum value. Both a minimum and a maximum value may be set.

If a minimum or maximum value is set, any formula associated with the Valid property is ignored. Instead, this property returns a logical value which takes the minimum and maximum values into account. In this context, blank values are considered valid.

Writing formulas determining if a field is valid

If your requirements go beyond minimum and maximum values, you must write a formula manually and associate it with this property to determine if a field is valid. This formula must return TRUE if the field is valid and FALSE otherwise.

This formula only considers odd numbers to be valid:

ISODD(NumberField1)ISODD(NumberField1)

We suggest that you consider blank field values to be valid. The alternative is for your users to be greeted by forms with validation messages already shown, which does not look inviting.

To consider blank values valid, use the ISBLANK function. Here's the formula above rewritten to accept blank values:

ISBLANK(NumberField1) || ISODD(NumberField1)ISBLANK(NumberField1) || ISODD(NumberField1)

(|| should be read as "or.")

Determining if a field is valid from a formula

On its own, the Valid property only shows a validation message and displays the field value in a different color if the field fails validation. Users are not prevented from moving on to a different screen or from pressing buttons, nor are any calculations inhibited.

Enable these features by accessing whether a field is valid from other formulas. For example, associate the following formula with the Value property of Field2 to prevent it from calculating a value unless Field1 is valid:

IF(Field1.Valid, Field1 * 100)IF(Field1,Valid; Field1 * 100)

If blank values are considered valid (which we recommend), you also need to use ISDEFINED to make sure that a value has been entered:

IF(ISDEFINED(Field1) && Field1.Valid, Field1 * 100)IF(ISDEFINED(Field1) && Field1,Valid; Field1 * 100)

(&& should be read as "and.")

To prevent a user from moving to the next screen, unless both Field1 and Field2 are valid and have defined values, associate a formula like the following with the NextScreenAvailable property of a form screen:

ISDEFINED(Field1) && Field1.Valid && ISDEFINED(Field2) && Field2.ValidISDEFINED(Field1) && Field1,Valid && ISDEFINED(Field2) && Field2,Valid

To prevent a user from pressing a button unless all fields of the Field1:Field5Field1:Field5 range are valid and have defined values, associate a formula like the following with the Enabled property of a button:

AND(ISDEFINED(Field1:Field5) && (Field1:Field5).Valid)AND(ISDEFINED(Field1:Field5) && (Field1:Field5),Valid)

The Field1:Field5Field1:Field5 range includes Field1 and Field5, as well as all fields appearing between them. (Field1:Field5).Valid(Field1:Field5),Valid returns a logical array like { TRUE, FALSE, TRUE, TRUE, FALSE }{ TRUE; FALSE; TRUE; TRUE; FALSE }, where each individual element indicates whether the corresponding field is valid.

ISDEFINED(Field1:Field5)ISDEFINED(Field1:Field5) also returns a logical array, where each individual element indicates whether the corresponding field value is defined (not blank). When && is applied to two arrays, a single logical array is returned, where each individual element is only TRUE if the elements at the same position in the two arrays are both TRUE. The net effect is that an array is returned, where each individual element indicates whether the corresponding field is both valid and has a defined value.

Finally, AND is applied to the resulting array and only returns TRUE if all elements of it are TRUE. The end result is that the formula only returns TRUE if all fields of the Field1:Field5Field1:Field5 range have defined values and are valid.

Examples

ISODD(NumberField1)ISODD(NumberField1)

Considers a number field to be valid only if its value is odd.

ISBLANK(NumberField1) || ISODD(NumberField1)ISBLANK(NumberField1) || ISODD(NumberField1)

Considers a number field to be valid only if its value is odd, or if it is blank. We recommend that blank values are considered valid, so as to not have forms warn users of erroneous values before any values have been entered.

IF(ISDEFINED(Field1) && Field1.Valid, Field1 * 100)IF(ISDEFINED(Field1) && Field1,Valid; Field1 * 100)

This formula is associated with the Value property of a number field. A value is only calculated if Field1 has a defined value and is valid. Otherwise, a blank value is produced.

ISDEFINED(Field1) && Field1.Valid && ISDEFINED(Field2) && Field2.ValidISDEFINED(Field1) && Field1,Valid && ISDEFINED(Field2) && Field2,Valid

This formula is associated with the NextScreenAvailable property of a screen. The user is only permitted to proceed to the next screen if Field1 and Field2 both have defined values and are considered valid.

AND(ISDEFINED(Field1:Field5) && (Field1:Field5).Valid)AND(ISDEFINED(Field1:Field5) && (Field1:Field5),Valid)

This formula is associated with the Enabled property of a button. The user is only permitted to press the button if all fields of the Field1:Field5Field1:Field5 range have defined values and are considered valid. The Field1:Field5Field1:Field5 range includes Field1, Field5 and all fields that appear between them.