Tip: Require a button to be pressed

Prevent users from seeing certain information, or from moving on to the next screen, if a button has not been pressed. This can be achieved through a formula button and a hidden field.

Sometimes, it is important for users to perform an action before they can proceed. For instance, you may want to require a button to be pressed before showing a calculated value.

Here’s an example app that demonstrates what we’d like to accomplish (try pressing the button):

As you can see, the extra information is only displayed once the button has been pressed.

With our new release, you can achieve this using formula buttons. A formula button runs a so-called action formula, which can take any action you like, including changing the active screen or sending an email back to the office with the collected information.

Of course, regular buttons can do all that too. What makes formula buttons appealing here is that they can perform multiple actions, including assigning values to fields.

In order to keep track of whether the user has pressed the button, we’ll add a hidden switch field, which we’ll name IsFormSubmitted.

Then, we’ll add a formula button, with the following formula associated with its OnPress property:

IsFormSubmitted := TRUE; EMAILREPORT(App, "office@example.com")IsFormSubmitted := TRUE;; EMAILREPORT(App; "office@example.com")

The formula above does two things: it sets IsFormSubmitted to TRUE, and it sends a report through email, containing all fields of the app, using the EMAILREPORT function. That function can do everything a regular email report button can, by setting the appropriate parameters.

Now that the IsFormSubmitted field reflects whether the button has been pressed, we can rely on its value from formulas.

The example app above has the following formula associated with the Visible property of the form group holding the results:

IsFormSubmittedIsFormSubmitted

The form group holding the contact form has the following formula associated with its Visible property:

NOT(IsFormSubmitted)NOT(IsFormSubmitted)

The formula above ensures that the contact form becomes invisible once the button has been pressed.

The OnPress formula above has one potential problem: it immediately sets IsFormSubmitted to TRUE. That means that users get access to the results even if the report is not sent successfully, which may not be what we want.

Here’s another version which waits for the EMAILREPORT function to notify us that the report has been sent successfully:

AWAIT(EMAILREPORT(App, "office@example.com"), IsFormSubmitted := TRUE)AWAIT(EMAILREPORT(App; "office@example.com"); IsFormSubmitted := TRUE)

(Note that even if a report is sent successfully, that does not mean that it will necessarily arrive at its destination, due to factors outside the control of your app.)

If you instead want to prevent users from moving on to the next screen until the button has been pressed, associate this formula with the NextScreenAvailable property of the screen:

IsFormSubmittedIsFormSubmitted

To learn more about how this property is set, refer to the blog post describing our new sample app, which has detailed instructions.

« Feature: Easily determine what fields to reset or include in a report Tip: Perform calculations when a button is pressed »