| 3.1. Specification Changes
Extend the METADATA-UPDATE_TYPE structure to include a reference (URL) to a body of code, written in JavaScript (ECMA). Including a URL is optional. The RETS GET Transaction can be used to retrieve the code for client-side validation. The retrieved script contains functions with well-defined signatures that can be called during validation of an update transaction.
The METADATA_VALIDATION-EXPRESSION metadata will no longer be needed and is eliminated by this change, as are references to it.
3.2. ECMAScript Function Signatures
Each function intended to be called during the validation process shall have a well-defined signature:
function(old_fields, new_fields, environment)
where old_fields is a JavaScript associative array containing the fields from the existing record, if any; new_fields is a JavaScript associative array containing the desired new values, and environment is a JavaScript associative array containing environment information as described below.
A script loaded from the URL specified in ValidationScriptURL shall have zero or more of the following functions, to be called at the indicated time:
| Function Name | Operation |
| validate_begin | Called when an editing session operating on a particular record is about to begin, before any other functions are called for that record. |
| validatename | Called when the field name has been changed by external action (that is, by the user or program, not by action of the validation script). |
| validate_for_submission | Called when all modifications to the data have been completed but before sending the Update transaction. |
These functions shall return an array of objects containing the following:
| Element Name | Content |
| field_name | The name of the field found to be in error, if the error is associated with a single field. |
| error_number | An error number that MAY be used in displaying error information. |
| error_is_fatal | An integer representing a Boolean value indicating that the error condition would preclude storing the record. An error in which this field is 0 or false MAY still allow storage on the server. |
| error_message | A string describing the error. |
3.4. Environment information
The environment parameter to the validation function shall be a JavaScript associative array containing the values in Section 4.9 of the RETS specification, as well as several additional items:
| Element Name | Content |
| .TODAY. | A value representing today's date, as defined by the application. |
| .NOW. | A value representing the current date and time. |
| .USER_AGENT. | A string containing the client's UserAgent identification. |
| .SESSION_ID. | A string containing the session ID for the current session, if any. |
3.5. Operation
The client software may use the script in whatever fashion is appropriate for the client's function. In an interactive client, the client MAY attempt to call a validatename function at the conclusion of editing the field with the given name, and present any error information to the user immediately upon the function's return.
In addition, the client MAY call the script's validate_for_submission at the end of the editing session, when the user indicates no further intent to change field values.
If the client intends to call any field or final validation function, it MUST call the validate_begin function, if any, before any fields have been changed. The client need not call any of the validatename functions even if it eventually calls the validate_for_submit function. |