PadCodedocs

A form that checks what's typed

Build a sign-up form whose fields say what's wrong as people type, and whose button checks again before going on.

What you'll build: a sign-up form with a name, an email address and a phone number. The email and phone fields say what's wrong while people type. Sign up, or Return in the last field, checks the form, puts the cursor where something's missing, and says thanks when it's all there.

What you'll learn:

  • Give a Text Field rules with Validation, and the keyboard that goes with them.
  • Check a form in steps, with If, Show Message and Stop.
  • Move the cursor to a field with Focus Field.
  • Run the same steps from a button and from the Return key.

#The variables

NameTypeStarting value
fullNameTextEmpty
emailTextEmpty
phoneTextEmpty

Make them in Data & Logic with Add variable. Each is named after its type, so tap each name and type the one from the table.

#Steps

#The fields

  1. Add three Text Fields. Set their Titles to Name, Email and Phone, and pick fullName, email and phone in their Text menus.
  2. Select the Email field. Under Validation, set Must be to Email.
  3. Select the Phone field and set Must be to Phone number. To say it your own way, type into Message, like Use digits, like 555 0100. Left empty, the app uses its own words.
  4. Rename the fields so steps can find them: in Layers, select each field, open the ⋯ menu on its row and choose Rename (or double-tap the row). Call them Name field, Email field and Phone field.
A Text Field's Style tab: under Validation, Must be is set to Email, and Message shows the message the app will use.

Must be offers these rules. Each also picks the keyboard, unless the field has a Keyboard Type modifier of its own.

Must beKeyboardMessage when the text doesn't fit
AnythingThe field's ownNone
EmailEmailUse an email address, like name@example.com.
Phone numberPhone padUse a phone number: digits, spaces, + ( ) and -.
NumberNumbers, with a decimal pointUse a number, like 12 or 3.5.
Whole numberNumbersUse a whole number, like 12.
Web addressWeb addressUse a web address that starts with https://.
Custom patternStandardThat doesn't match the pattern.

Custom pattern adds a Pattern box for a regular expression the whole text must match, like [A-Z]{2}[0-9]{4}.

#The checks

The button and the Return key both check the form, so the steps go in a reusable action.

  1. In Data & Logic, under Reusable actions, tap New action. Add these steps:
StepSettings
IfCondition isEmpty(trim(fullName)). Under Then: Show Message (Text Add your name, Style Warning), Focus Field (Id Name field), Stop.
IfCondition !contains(email, '@'). Under Then: Show Message (Text Check your email address, Style Warning), Focus Field (Id Email field), Stop.
Show MessageText Thanks, {fullName}!, Style Success
  1. Tap Done, then tap the action's name, newAction, and change it to signUp.

#Run them

  1. Add a Button titled Sign up. In its Actions tab, add Run Action and pick signUp under Action.
  2. Select the Phone field. In its Actions tab, tap the When card and choose When Return Is Pressed. Add Run Action with signUp here too.

Tap Preview. Type maya@ in the Email field: the message shows under it. Tap Sign up with the name empty: a message asks for it, and the cursor jumps to the Name field.

Preview: the Email field holds maya@, and red text under it says Use an email address, like name@example.com.

#How it works

  • Validation looks at the text each time it changes and writes what's wrong under the field, in red. An empty field shows no message: it only judges what's been typed.
  • Validation doesn't stop anything. A button or a Return key still runs its steps while a field shows a message. That's why the steps check again before going on.
  • The checks: isEmpty(trim(fullName)) is true when the name is empty or only spaces. Formulas can't run the Email rule itself, so !contains(email, '@') is a rough stand-in; Invoice Maker makes the same check before it sends an invoice.
  • Stop ends the run. The thank-you only shows when no If stopped it.
  • Focus Field finds a field by its name in Layers (or its id), so the fields need names you chose.

#See also