• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 3. Layout Enhancements > Creating Field Masks

Creating Field Masks

Many database programs have the ability to format data like phone numbers and Social Security numbers automatically. If you enter 2125551234 in the phone field, you'll see (212) 555-1234 instead. FileMaker Pro does not offer this feature, but you can mimic it on a layout. If you place a locked, formatted display field directly over an unlocked entry field, you mask the bottom field while still leaving it active. Connect the two fields with a calculation, and whatever value you enter displays properly in the field above it.

To create a field mask:

Go to a layout with a field you'd like to mask. Choose File > Define Fields (Ctrl+Shift+D/Command-Shift-D).

When the Define Fields dialog box appears, select your existing field and change its type to Number if it was created as a Text field. This example uses the Phone field (Figure 3.44).

Figure 3.44. To format a phone number, it must be a number field.

Create a new field with the word Mask in the Field Name line (like Phone Mask or Credit Card Number Mask), select Calculation as the Type and click Create (Figure 3.45).

Figure 3.45. After you've verified that your Phone field is a number, create a new field for your mask by choosing calculation as the type and clicking Create.

When the Specify Calculation dialog box appears, click the quotes button and type ( between the quotes (Figure 3.46).

Figure 3.46. To make a parenthesis appear before the phone number, type it between quotes.

Click to the right of the quotes and then click the ampersand button (Figure 3.47). Double-click Left in the Function list on the right to add it to the calculation in the formula builder window (Figure 3.48).

Figure 3.47. Click the ampersand (&) operator button to link functions together.

Figure 3.48. The Left function counts characters from the left of the field to separate them from the rest of the field contents.

Left will format the area code of the phone number by separating the first three numbers from the rest of the contents of the field.

Double-click “text” in the Left calculation to highlight it, then double-click Abs in the Function list. Abs will replace “text” in the calculation (Figure 3.49).

Figure 3.49. To replace a parameter with a function, select the parameter in the formula builder, then double-click the function in the function list.

If the user enters a parenthesis at the beginning, FileMaker will assume that the number is a negative. The Abs function will return the entry as a positive.

With the first “number” highlighted in the formula builder, double-click Phone in the Field list (Figure 3.50).

Figure 3.50. With the Abs “number” parameter highlighted, select the field you want to connect to your mask.

Highlight the remaining “number” and type 3 (Figure 3.51).

Figure 3.51. To specify how many numbers should display after the first parenthesis, replace the parameter with that number. (For an area code, you type “3.”)

The number parameter specifies how many numbers the Left function should put inside the parentheses. Since this is an area code, you type 3.

Move your cursor to the end of the formula. Click the & operator button, then the quotes operator button and type ) inside the quotes.

Move your cursor to the end of the formula and click the ampersand button. Add the Middle function by double-clicking it in the right Functions list (Figure 3.52).

Figure 3.52. To add a function to a series of calculations, click the & button and then double-click the formula from the function list.

The Middle function works like the Left function, but instead of counting from the far left, begins counting at whatever character number you type in the “start” parameter, for the number of total characters you specify in the “size” parameter.

Use copy and paste to replace “text” in the Middle function with “Abs(Phone)” from the first part of the calculation.

Double-click “start” and replace it by typing 4, then select “size” and replace it by typing 3 (Figure 3.53).

Figure 3.53. To specify the second part of the telephone number, replace “start” with 4 and “size” with 3.

To specify the second part of the telephone number, the 4 represents which number in the sequence begins after the area code. The 3 represents how many digits will follow.

Move your cursor to the end of the formula. Click the ampersand button and then the quotes button. Type a hyphen (-) between the quotes

Move your cursor to the end of the formula, then click the ampersand button. Add the Right function by double-clicking it in the function list.

Replace “text” with “Abs(Phone)” again, then double-click “number” and replace it by typing 4.

Click OK (Figure 3.54) and then Done to close the Define Fields dialog box. You've finished creating the Mask field.

Figure 3.54. After completing your formula, click OK.

Go to the layout where you want the formatted field and switch to Layout mode (Ctrl+L/Command-L).

Select your Phone field, or create one if necessary.

Duplicate the field by clicking and dragging it while holding down the Alt (Windows)/Option(Mac) key.

In the Specify Field dialog box, uncheck Create field label and select Phone Mask from the list (Figure 3.55), then click OK.

Figure 3.55. To avoid creating an unnecessary field label, uncheck the Create field label check box when you make the Mask field.

While the Phone Mask field is selected, choose Format > Field Format (Ctrl+Alt+F/Command-Option-F) .

When the Field Format dialog box appears, uncheck Allow entry into field, then click OK (Figure 3.56).

Figure 3.56. Lock a field by unchecking Allow entry into field.

This prevents data from being entered into the Mask field. When the user clicks on this field, the cursor will actually go into the entry field behind it.

Make sure that the Fill for the Mask field is set to Opaque (Figure 3.57).

Figure 3.57. Setting the mask field to Opaque prevents the entry field beneath it from showing through.

Drag the Phone Mask field so that it is squarely on top of the Phone field.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint