Data Validation in Interactive Forms

Uniface validation can be initiated by a focus change in a form component, or by ProcScript commands in any type of component.

In form components, validation is automatically initiated when the user navigates out of a modified object. By default, a field is prevented from losing focus when validation fails, but this can be changed by redefining the error triggers.

You can check whether a field, key, or occurrence requires validation using the ProcScript functions $fieldvalidation, $keyvalidation, or $occvalidation.

Validation Process in Interactive Forms

For Uniface forms that are run interactively, events that change focus fire event completion triggers such as loseFocus and leaveModified, and start implicit validation.

Uniface first checks declarative validation constraints, then activates the validation triggers, followed by their respective event completion triggers:

  • Field: validate->loseFocus
  • Field: validateKey->leaveModifiedKey
  • Entity: validate->leaveModified

For example, when the user moves the cursor from a key field KeyField to a non-key field and the key is complete, the trigger activation sequence is as follows:

  1. validate (KeyField)
  2. loseFocus (KeyField)
  3. validateKey
  4. leaveModifiedKey

Any event that changes the focus, such as going to another field with the ^NEXT_FIELD structure editor function, starts the validation process. (The structure editor functions ^ACCEPT and ^STORE leave the active path and consequently carry out all outstanding data validation on the active path just left.)

Use the validation triggers to define business rules that cannot be specified declaratively. Use the event completion triggers to handle user interface issues.

The loseFocus trigger deals with the presentation logic, while the validate trigger deals with business logic.

trigger loseFocus; of Field
  if ($fieldendmod)
   if (CUSTCODE = ’Special’)
     $prompt = SPECIAL_DISCOUNT ;next field
     $fieldsyntax (DISCOUNT) =  "DIM" ;make inaccessible
   else
     $fieldsyntax (DISCOUNT) =  "" ;make accessible
   endif
endif
return
end; loseFocus

;----------------------------
trigger validate ; of Field
if (DISCOUNT >= 0 & DISCOUNT <= 100))
   return(0)
else
   return(-1)
endif
done
end; validate