OnValidate - cWebBaseDEO
Fired to validate control data
Type: Event
Return Data Type: Boolean
Syntax
Function OnValidate Returns Boolean
Description
Fired to validate control data.
OnValidate is intended primarily for non data-aware controls. With data-aware controls, you should do the data validation in a DataDictionary class or DDO. When not augmented in your own code, OnValidate calls File_Field_Validate_Field of the DDO when the control is connected to a DDO.
Set pbServerOnValidate to True for the server side even to fire.
Set pbServerOnValidate to True
Function OnValidate Returns Boolean
String sValue
Boolean bRetVal
Forward Get OnValidate to bRetVal
WebGet psValue to sValue
If (sValue <> "test") Begin
Move False to bRetVal
End
Function_Return bRetVal
End_Function
Sample
This sample shows how to make sure user entry stays between 0 and 4. If the user enters a value outside that range, set it lowest or highest allowed value.
Object oProductSize is a cWebForm
Set piColumnSpan to 3
Set psLabel to "Size"
Set piColumnIndex to 4
Set peDataType to typeNumber
Set psMask to "#.#"
Function OnValidate Returns Boolean
Boolean bRetVal
Short siVal
Forward Get OnValidate to bRetVal
WebGet psValue to siVal
If (siVal > 4) Begin
WebSet psValue to 4
Move False to bRetVal
End
Else If (siVal < 0) Begin
WebSet psValue to 0
Move False to bRetVal
End
Function_Return bRetVal
End_Function
End_Object
Desktop vs Mobile Browser Behavior
In desktop browsers, OnValidate triggers when tabbing (forward navigating) the next form. So not every blur causes a validate. This is by design, as we don't want OnValidate to trigger when, for example, you click a toolbar item. A save will also trigger the same validation.
Mobile browsers do not support proper events to handle a click on this 'next field button' shown on many mobile keyboards. So there is no hook for us to use for OnValidate during forward navigation. Thus, on mobile browsers, OnValidate is only performed when a record is saved.
You can try using OnBlur for validation on mobile devices, but it will likely be called too often.
Return Value
Return False to keep the focus in the current control.