Chapter 6 you looked in some detail at ways of applying business logic through the use of XML schemas, rule-based validation, and scripting. Here you’ll study some simple interface design methods that you can use with forms that are built from scratch.Most of the time you’ll be working with the Data tab on the control’s Properties dialog box. We assume that by now you are quite familiar with the design mode interface, and our tips will therefore be summaries of actions rather than step-by-step instructions.
When a user saves a form containing data type errors or missing data, an error is displayed in a dialog box alert. Users can save invalid forms, but they can’t submit these forms to a database, Web service, or other location.
InfoPath Data Types
If you develop a form from scratch with a blank form, building a schema as you go, you can assign an InfoPath data type to the control, or more exactly to the data source for the control. The following table gives the data types that you can use for text boxes and lists. The second column shows the equivalent XML schema data type.
InfoPath Type | Schema Type | Use |
|---|---|---|
Text | string | Data such as names, addresses, phone numbers, social security numbers, and so on |
Whole Number | integer | Positive or negative whole numbers, such as 1234, -1234, or $1,234 |
Decimal | double | Numbers with decimal places, such as 1234.12, -1234.12, or $1234.12 |
True/False | boolean | Data that should be either 1 (true) or 0 (false) |
Hyperlink | anyURI | Hyperlinks, such as [http://w3c.org] |
Date | date | Dates, such as 3/14/2007 or March 14, 2007 |
Time | time | Time, such as 9:46:55 or 09:46 A.M. |
Date and Time | dateTime | Both date and time, such as 3/14/2007 11:30 A.M. |
For example, if you want users to enter a value in euros into a text box for an amount, you can choose the decimal type and formatting options so that values typed in the text box are displayed with the € currency symbol.If a user then types the wrong type of data, an inline alert appears. This takes the form of a dotted red line around the control. If the user right-clicks or moves the mouse pointer over the text box, additional information about the nature of the problem appears, in this case the error message “Only number allowed,” as shown in Figure 11-1.
Figure 11-1: An inline alert.
Required Input
You can also specify that form data is required. When users open the form, a solid red underline appears under any controls that require data. As soon it is entered, the red underline disappears. This underline may not be prominent enough for all users, so you might consider using some additional formatting, for example, shading the background of the control if it is blank.To set a control to required, select the Cannot be blank check box on the display tab of the Properties dialog box. When it is set, a screen hint appears when the cursor is over the control.
Setting Defaults
You can specify default values for controls. An example from our case study is that most stories are of the “Article” type. When a contributor adds a story of another type, or an editor decides to change it, they can type over the default value. Defaults can be set in two ways. If the form schema contains a fixed element or attribute value, InfoPath will make that a default. Alternatively, you can enter or select a default on the Data tab of the Properties dialog box. The value is saved in the form template.
Read Only
If the contents of a control is fixed by default or set by script rather than users, you can choose to make it read-only to prevent users from making unwanted changes. You can do so by choosing the Read-only check box on the Display tab of the Properties dialog box.