Tutorial: Forms and Validation
- Employee Manager Relationship. Each employee manages one to many subordinates. This is called a one-to-many relationship. In the data model, this relationship is represented by a foreign key column in the employee table that stores the id of that employee's manager.
- Vacation Request Relationship. Each vacation request must have a related employee. This is called a one-to-one relationship (each vacation must have one related employee). In the data model it is represented as a foreign key in each row of the vacation table containing an employee id.
- Create a new project.
- Set the project name to: ValidationApp
- Set the project theme to wm_default
- Set the project template to the Tabs Template
- Import the hrdb database
Validate text input
A form contains an editor for each column in a database table. Here are some things to know about data editor validation:- All editors validate the input data based on the data type. For example, a number editor will not allow the user to enter anything other than the digits 0 to 9
- The developer can set editor properties to add additional validation, such as minimum and maximum values for a number or maximum length for a text string
- The developer can also add help and error messages to display to the user
- Drag the Department database widget onto the canvas.

- Select the Traditional LiveForm option and click OK.
- Select the LiveForm Name editor, which is located on the lower half of of the web page.

- Examine the Properties for the Name editor widget.

Here is a brief description of the Common editor properties:- name: name of widget
- showing: if unchecked, this widget will be invisible
- formField: this is the name of the database column that this editor is connected to
- Examine the Editor Options properties for the Name editor widget.

Here is a brief description of the Editor Options properties:- readonly: if this is checked, the data value of this editor cannot be changed
- password: if this is checked, the letters entered by the user will not be visible on the screen. This is useful for password fields.
- maxChars: specifies the maximum number of characters a user can enter into this editor
- Set the maxChars property for the editor to 10
- Click the
Run button. - In the running application click the New button at the bottom of the Department form to create a new department
- Click in the Name field.
- Try to enter a name longer than 10 characters. Note that the text editor refuses to accept more than 10 characters
Validate numeric input
A form contains an editor for each column in a database table. To validate a numeric input, follow these steps:- Now select the Budget editor in the canvas

- Set the promptMessage property for the Budget editor to: Enter a budget between 1 and 100.
This message will be displayed as a tooltip when this editor is selected.
- Set the minimum property to: 1
- Set the maximum property to 100
- Set the rangeMessage property to: Number out of range.
This message will be displayed when the user tries to enter a number less than one or greater than one hundred
- Click the
Run button. - In the running application click the New button at the bottom of the Department form to create a new department
- Click the Budget editor in the form. Note the tooltip that appears when the Budget field is entered

- Enter the number 200. Note that an error message appears

Set default values
A form for a database widget takes its value from the currently selected row. The defaultInsert property of an editor allows the developer to specify what the default value should be. To set the defaultInsert property for the budget editor, follow these steps:- Now select the Budget editor in the canvas

- Set the defaultInsert property for this editor to: 50
Note: You may have to scroll the property list to find the defaultInsert property.
- Click the
Run button. - In the running application click the New button at the bottom of the Department form to create a new department
- Note that the value for Budget was automatically set to 50

Set default date
The defaultInsert property for each live form editor provides a way to set the value for that property when creating a new database row. To set a date editor to default to today's date, follow these steps:- Select Tab2 in the canvas
- Drag a Vacation database widget into Tab 2.

- Select the Traditional LiveForm and click OK.
- Select the Startdate editor in the form for the vacation database widget

- In the Property panel defaultInsert property, click the bind button

This brings up the Binding Editor - At the top of the Binding Editor, select the Expression radio button. This allow you to enter simple Javascript commands to set the defaultInsert value
- Enter the Javascript command: new Date().

This creates a new date with today's date. - Click the Bind button to close the Binding Editor. Note that the binding shows up in the defaultInsert property.

- Click the
Run button. - Click on Tab 2 to bring up the vacation database live form.
- Click the New button to create a new vacation entry
- Note that the default start date is set to today's date

Forms With "To-One" Relationships
A RelatedEditor is a specialized select editor for use in LiveForms. A RelatedEditor is used to set relationships between tables, such as setting the employee relationship for a vacation request. Here are some things to know about RelatedEditors:- RelatedEditors for relationships that are required by the database are generated automatically (technically, required relationships are relationships where the foreign key value is not allowed to be null).
- RelatedEditors for optional relationships can be added by dragging a RelatedEditor widget into the appropriate LiveForm and setting the formField property.
- Each RelatedEditor is a container widget that contains a lookup editor in the case of a "to-one" relationship and a grid in the case of "to-many" relationship
- Click on Tab 2 to bring up the vacation database widget
- Click on the "Employee (lookup)" editor

- Make sure that that Property panel shows that the currently selected widget is employeeLookup1. This is the lookup editor located inside the RelatedEditor

- Press the Escape key to select the RelatedEditor widget that contains employeeLookup1

Note: pressing the Escape key selects the parent widget. - Examine the Properties for the RelatedEditor widget.
Here is a brief description of the common Editor properties:- name: name of widget
- editingMode: the options are lookup, which is done using a select editor; read only, which does not allow the relationship to be changed; and editable subform, which allows editing of individual fields in the related table.
- formField: name of relationship set by this RelatedEditor. Typically, this will be the table name of the related table
Forms with "To-Many" Relationships
A RelatedEditor for a "To-many" relationship shows data from related tables in a grid. Here are some things to know about RelatedEditors for a "To-Many" Relationship:- A RelatedEditor for a "To-many" relationship shows all of the rows in the related table which are associated with the selected row. For example, it can show all of the vacation requests for a particular employee.
- Select Tab 3 in the canvas
- Drag an Employee database widget into Tab 3
- Select the Traditional LiveForm and click OK.
- Now drag a RelatedEditor into the Employee Details form

- Set the formField property for the RelatedEditor to "vacations"

- Note that the RelatedEditor now contains a grid with all the vacation requests for the currently selected Employee

Set RelatedEditor default value
The defaultInsert property for a LiveForm's RelatedEditor provides a way to set the value for that property when creating a new database row. To set the default value for a RelatedEditor in a LiveForm, follow these steps:- Click on Tab 2 to bring up the vacation database widget
- Click on the "Employee (lookup)" editor

- Examine the Properties for the lookup widget.

- Now scroll down to view the Editor Data properties

Here is a brief description of the Editor Data properties::- displayValue: this is the value displayed by default
- dataValue: this is the data value returned by the widget
- emptyValue: this is the value returned by the widget if the user doesn't enter anything (technically, this is the value returned for NULL input)
- defaultInsert: this is the default related data to use when creating a new database row
- Click the bind icon to the right of the defaultInsert property to bring up the Binding Editor
- Select the employeeDojoGrid from the widget menu

This will set the default related employee for a new vacation request to the currently selected employee on Tab 3. - Click the Bind Button to accept the binding
- Click the
Run button. - In the running application click Tab 3 then click on an employee
- Select Tab 2 and click the "New" button to create a new vacation request
- Note that the default related employee for this new vacation request is the employee selected on Tab 3

You have completed the Forms and Validation Tutorial. PDF version of this tutorial Continue on to Tutorial: Security
on 21/02/2012 at 17:12


