Data Validation

One of the main purposes of Commerce Server Business Desk is to provide a way for business managers to change the data that determines how their Web site appears to users. Such changes can consist of changing existing data, adding new data, or deleting old data. Several types of errors can occur when data is entered. The entered data might not be of the correct type, or it could exceed the allowable range of values. When a new record is being created, some of the required data could be missing. Further, there could be inconsistencies between various fields in a record based on dependencies between those fields.

Some types of errors are relatively easy to detect and handle in a generic way. Such errors are handled automatically within the relevant HTML Components (HTCs), completely on the client-side. Such errors include:

  • Enforcement of minimum and maximum allowable values for numbers, dates, and times. The min and max attributes of some types of child elements of the fields element are used to specify these restrictions, which are enforced when the input field loses focus.

  • Enforcement of a maximum and minimum length for text input. The maxlen and minlen attributes of some types of child elements of the fields element are used to specify these restrictions, which are enforced when the input field loses focus.

  • Enforcement of matching a particular pattern of characters. The charmask child element of some types of child elements of the fields element is used to specify such pattern restrictions, which are enforced when the input field loses focus.

  • Enforcement of certain formats. The format child element of some types of child elements of the fields element is used to specify such formats, which are enforced when the input field loses focus. Date and Numeric types support different formats.

  • Enforcement of required fields being supplied with a non-empty value. The required attribute of some types of child elements of the fields element is used to specify this restriction, which is enforced when the user commits changes.

The Business Desk user is notified of these types of errors as soon as they are detected, before the erroneous values are sent to the server for subsequent processing. Errors are reported using client-side modal dialog boxes that provide the Business Desk user with a standardized error message, or in the case of the pattern matching errors, a customized error message that is specified in the XML configuration information along with the pattern itself. Once the invalid data dialog box is dismissed, the field or fields that caused the error are marked to draw the attention of the Business Desk user to those fields.

Some types of data validation are more involved and must be handled by the module in a custom manner, usually on the server-side. These types of validation include uniqueness checking across records and cross-field validation. When these types of errors occur, the module is responsible for displaying an appropriate error message, re-displaying the page upon which the error was made, and restoring the state of that page.

A common technique for performing cross-field data validation in client-side code is to trap the OnChange event provided by many of the Business Desk HTCs. You can write a handler function for the OnChange event that, for example, performs consistency checking between different fields on the page, or which forces a user-supplied value into a more acceptable format. The following HTCs support the OnChange event:


All rights reserved.