Extending Forms with Formatting and Validation


At this point, the form layout and entry are complete. The problem is that the form doesn t contain any specific validation or business logic needed to verify the user - entered data. This is logic applied outside the default schema and may be specific to the form instance. InfoPath enables form designers with this type of control through conditional formatting and applying specific data validation rules to the form.

Conditional Formatting

Conditional formatting enables designers to control the formatting of rich-text boxes, sections, and repeating tables based on a set of predefined conditions. These controls can change their appearance based on a set of values entered during form design. Each control can maintain a set of conditions ”such as style, font, color , text background, and visibility ”that can be associated with a set of rules. Controls can maintain multiple conditional formatting rules that are stored as part of the XSLT within the solution file. Whenever the defined condition is met, the rule is applied and rendered to the form.

Within the Timesheet application, one of the business requirements is that the cost center field be less than 4000. Within the designer, you can double-click on the cost center field and from the display window enter the conditional formatting, as shown in Figure 3.16.

click to expand
Figure 3.16: Adding the conditional formatting.

It is always important for designers when doing any type of formatting or validation to preview and test the form. This will ensure that the form is working correctly and that the defined rules are functioning as expected. To do this, select the Preview Form button within the design mode. The word Preview appears in the title bar to inform designers they are in a preview window. During a form preview, the form is simulated and certain menu command and toolbar options (like the Save command) are disabled.

Data Validation Rules

In addition to conditional formatting, one of the main requirements of data-driven applications is data validation. InfoPath can handle this in a couple of different ways. At the lowest level is schema-based validation. Within the  timesheet.xsd , this was done through restrictions applied to the base elements. InfoPath automatically validates the data entered into forms against the expected data stored in the data source as a way of enforcing schema requirements. InfoPath also provides a declarative- or rules-based engine that enables designers to apply this type of logic. When you use the data validation engine, rules are always associated with a specific control and validation occurs when the user fills out a form. InfoPath validates the data by checking the value entered into the field against the rule stored in the data source to which the control is bound. Each of these methods may also be extended with script-based validation using the InfoPath object model. Validation always occurs at the field level, and depending on the complexity of the form multiple rules may be applied to a field within the data source. Table 3.2 shows the type of validation that is available within InfoPath.

Table 3.2: Types of validation supported by InfoPath.

Validation Type

Description

Required Controls

Requires that users enter a value into the control

Data Type Validation

Requires that users enter a particular type of data that matches the type of the control

Range Checking

Ensures that the value entered into a control is within a specified range

Dynamic Comparisons

Compares the values in different controls and then validates a condition

Script-based Validation

Uses a script to perform an advanced validation on a control

The rules-based engine built into InfoPath allows form designers to display an error alert when incorrect values are entered into a form. InfoPath validates data when a user leaves the control, as opposed to what Web applications do, which is typically validate only when a form is posted. This provides the end user with immediate feedback on the state of his form. As opposed to conditional formatting, any errors defined within data validation prevent the form from being submitted to a database or Web Service. Users can save the form locally or navigate through the form using the tools menu and correct errors.

InfoPath provides an inline and dialog box error notification. The inline alert marks the control that reported the error with a dashed red border. The dialog error displays a modal form with a custom error message when invalid data is entered. End users who are completing a form can right-click and display the error message for further information.

For example, one of the business requirements for the Timesheet application was to enforce a vacation day rule for employees . The rule required that any employee who selected the work type of Sick couldn t report more than eight total hours for the day.

Within the properties, we could define the rule shown in Figure 3.17 to en-force this.

click to expand
Figure 3.17: Defining the employee absence requirement.

Striking a balance between conditional formatting and data validation is an important requirement in making forms that are easy for end users to complete.




Programming Microsoft Infopath. A Developers Guide
Programming Microsoft Infopath: A Developers Guide
ISBN: 1584504536
EAN: 2147483647
Year: 2006
Pages: 111
Authors: Thom Robbins

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net