PROMPT.NUMBER function

PROMPT.NUMBER(Body, Title?, InitialValue?, CancelLabel?, OkLabel?, OkButtonEnabled?) PROMPT.NUMBER(Body; Title?; InitialValue?; CancelLabel?; OkLabel?; OkButtonEnabled?)

Body

Text

The body of the prompt.

Title

Text (optional)

The title of the prompt. If omitted, no title is used.

InitialValue

Number (optional)

The initial value of the field that the user edits. If omitted, the initial value is blank.

CancelLabel

Text (optional)

The label of the cancel button. If omitted, a default label is used, whose exact wording depends on the language the app has been configured to use. "Cancel" is used for apps in English.

OkLabel

Text (optional)

The label of the OK button. If omitted, a default label is used, whose exact wording depends on the language the app has been configured to use. "OK" is used for apps in English.

OkButtonEnabled

Logical (optional)

A formula fragment that is expected to return TRUE if the OK button should be enabled and FALSE otherwise. To do its work, it has access to the entered value under the name Input. If omitted, the OK button is always enabled.

Returns

Promise

A promise, which succeeds if the OK button is pressed, returning the entered number, and fails if the cancel button is pressed. Pass this promise as the first parameter to AWAIT (and related functions) to take action after the promise has succeeded or failed.

Prompts the user for a number and returns a promise with the entered value. AWAIT(PROMPT.NUMBER("Enter a number:"), BANNER("You entered " & Result))AWAIT(PROMPT.NUMBER("Enter a number:"); BANNER("You entered " & Result)) asks the user for a number and displays it once it has been entered.

This function can only be used from an action formula. It is typically invoked from a formula associated with the OnPress property of a formula button.

The Title parameter may be used to set the title of the prompt. Use InitialValue to provide the value of the number field the user edits when the prompt is first shown. If either parameter is omitted, a blank value is assumed.

The prompt has a cancel button and an OK button. The labels may be set using the CancelLabel and OkLabel parameters, respectively. If a label is omitted, a label appropriate for the language of the app is used.

To prompt the user for a text string, use PROMPT instead.

Reading the entered number

PROMPT returns a promise, effectively promising to return the entered value at some point in the future. Use AWAIT to read the value.

The first parameter to AWAIT should be the promise returned from PROMPT and the second parameter should be a formula fragment that is run when the user presses the OK button. The formula fragment has access to the entered value under the name Result.

This formula asks the user to enter a value and then stores this value as the hidden field Concentration before sending a report containing that field and the Volume field:

AWAIT(PROMPT.NUMBER("Enter concentration:", Title: "Input"), Concentration := Result; EMAILREPORT({ Concentration, Volume }, "test@example.com"))AWAIT(PROMPT.NUMBER("Enter concentration:"; Title: "Input"); Concentration := Result;; EMAILREPORT({ Concentration; Volume }; "test@example.com"))

The formula stores the value using :=, which assigns values to properties. ;;; separates actions in an action formula, which are run one after the other.

The OK button of the prompt is enabled at all times, meaning that any number is accepted. For a formula that only accepts positive values, see below.

Determining if the OK button should be enabled

The OkButtonEnabled parameter may be set to a formula fragment which returns whether the OK button is enabled. To do its work, it has access to the input number provided by the user, under the name Input. The formula fragment is run every time the user makes a change to determine if the OK button should be enabled.

This formula only enables the OK button if the entered number is positive:

PROMPT.NUMBER("Enter a value", Title: "Input", OkButtonEnabled: Input > 0)PROMPT.NUMBER("Enter a value"; Title: "Input"; OkButtonEnabled: Input > 0)

This formula only enables the OK button if the entered number is greater than or equal to the value of the field MinimumConcentration:

PROMPT.NUMBER("Enter the concentration:", Title: "Input", OkButtonEnabled: Input >= MinimumConcentration)PROMPT.NUMBER("Enter the concentration:"; Title: "Input"; OkButtonEnabled: Input >= MinimumConcentration)

Asking multiple questions

With AWAIT, an arbitrary number of questions can be asked in succession. As an exercise, let's write a formula that asks a user their name and age and displays this information.

This formula asks the user for their name and displays it as a banner:

AWAIT(PROMPT("What's your name?"), BANNER("Hi " & Result & "!"))AWAIT(PROMPT("What's your name?"); BANNER("Hi " & Result & "!"))

We need to expand on this formula and ask the user's age too. Here's a first attempt:

AWAIT(PROMPT("What's your name?"), AWAIT(PROMPT.NUMBER("How old are you?"), BANNER("You're " & Result)))AWAIT(PROMPT("What's your name?"); AWAIT(PROMPT.NUMBER("How old are you?"); BANNER("You're " & Result)))

That works, but the banner only displays the age of the user, not their name.

Displaying both collected text strings presents us with a problem: as the entered age is available under the name Result, there is no way to access the entered name, which is also available as Result. Essentially, the new invocations of AWAIT and PROMPT overwrite the name with the age, making the name inaccessible.

This problem can be solved by renaming the results returned from AWAIT using ->, making them available under distinct names:

AWAIT(PROMPT("What's your name?"), Name -> AWAIT(PROMPT.NUMBER("How old are you?"), Age -> ALERT("Your name is " & Name & " and you're " & Age & ".")))AWAIT(PROMPT("What's your name?"); Name -> AWAIT(PROMPT.NUMBER("How old are you?"); Age -> ALERT("Your name is " & Name & " and you're " & Age & ".")))

Examples

AWAIT(PROMPT.NUMBER("Enter a number:"), BANNER("You entered " & Result))AWAIT(PROMPT.NUMBER("Enter a number:"); BANNER("You entered " & Result))

Asks the user for a number and displays it once it has been entered.

AWAIT(PROMPT("What's your name?"), Name -> AWAIT(PROMPT.NUMBER("How old are you?"), Age -> ALERT("Your name is " & Name & " and you're " & Age & ".")))AWAIT(PROMPT("What's your name?"); Name -> AWAIT(PROMPT.NUMBER("How old are you?"); Age -> ALERT("Your name is " & Name & " and you're " & Age & ".")))

Asks the user for their name, then asks the user for their age, and finally displays an alert containing the information the user entered. The information the user enters is available as the values Name and Age, which is accomplished using ->.

AWAIT(PROMPT.NUMBER("Enter concentration:", Title: "Input", OkButtonEnabled: Input > 0), Concentration := Result; EMAILREPORT({ Concentration, Volume }, "test@example.com"))AWAIT(PROMPT.NUMBER("Enter concentration:"; Title: "Input"; OkButtonEnabled: Input > 0); Concentration := Result;; EMAILREPORT({ Concentration; Volume }; "test@example.com"))

Asks the user to enter a concentration and then assigns this number to the value of the Concentration field, which it then sends in a report to test@example.com, along with the Volume field. The OK button is only enabled if the entered number is positive.

AWAIT(PROMPT.NUMBER("Enter value:", InitialValue: StoredValue), StoredValue := Result)AWAIT(PROMPT.NUMBER("Enter value:"; InitialValue: StoredValue); StoredValue := Result)

Asks the user to provide a value and then stores this value as the value of the hidden field StoredValue, which retains its value even when the app is closed. The initial value of the prompt is set to the value of StoredValue, ensuring that the user is presented with their previously-entered value the next time the formula is run.