Quick Objects Documentation Akal Tech Logo
Adding Validation To Fields

Glossary Item Box

Designer - How To:

One of the powerful feature in Quick Objects Designer allows you add Validation criteria to fields. This criteria gets saved with your project, and every time you re-generate your base classes, the validation code is automatically updated to reflect the validation defined in the designer.

By default the Business Logic Framework automatically assigns a BaseFieldValidator to each field. This is limited to enforcing column level constraints defined in your database, such as NOT NULL or the maximum length of the field etc.

Before the release of version 3.5 a developer needed to write the validation code by hand. Even though a adding a single validator only needed about 2-3 lines of code, but we wanted to streamline the process even further and reduce the amount of time it would take to change such validation rules.  Starting version 3.5 not only the validation framework is improved, but you can use the Designer to add validation rules and have it generate the code for you.

In this tutorial we will walk through the basic steps involved in adding a validator.

Prerequisite:

Start the Quick Objects Designer, and then open the "*.qos" file of your choice, or get the schema from a database and save a new qos file. For this example, we have used the QO_SHOP sample database included with the installation of the product.

1. From the tables grid on the left, select the table and then on the Columns tab, select the column where you would like to add certain validation. In our example, we have selected the Users table, and Email column.


EnlargeClick to enlarge

 

2. Right next to the Column's Properties tab, there is a tab called Validators. Select the Validators tab, and then click on the "Add" button on the toolbar inside the Validators tab.


EnlargeClick to enlarge

3. From the drop down menu choose the "Regular Expression", and you will be shown the properties of the Regular Expression validator.


EnlargeClick to enlarge

EnlargeClick to enlarge

 

4. The Custom Error Message is a excellent way to customize your validator. Each type of validator provides different options that can be used to format the resulting error message of a validator. Essentially when a validator fails and the ErrorString property is requested, instead of returning the standard error message a formatted/customized error message is returned. This gives you complete control over what should be displayed when a validation fails.

 


EnlargeClick to enlarge
As you will see that a hint is displayed that shows you all the available options.
 
5. Regular Expressions: You can utilize the Sample Expressions already available to get a jump start on specifying the regular expression that will be used for validation.  Of course you can directly specify your expression in the "Regular Expression" text box if you prefer.
From the Sample Expressions drop down select the Email option and it will automatically set the Regular Expression text box value.

EnlargeClick to enlarge
 
6. Is Null Valid: This checkbox can be used to specify if the validator will treat the IsNull property of the field as a valid value or not.

EnlargeClick to enlarge
 
7. Click Ok button on the toolbar to add the validator to the Email field. You will need to save the project (.qos) file before generating the code. Once you regenerate the base classes, the validation code will automatically get generated. In future you can make changes to this validator or add new ones or remove this one and regenerate the base classes to have the latest validation code be generated for you automatically.

EnlargeClick to enlarge