beautypg.com

Not restore old contents – Kofax DOKuStar Validation User Manual

Page 102

background image

DOKuStar Validation for Ascent Capture

Page

98

Not Restore Old Contents

When a scripting routine returns

False

in the

OnFieldChanging

event, the original contents of the field

(before the user changed it) is restored.

Sometimes however it might be better to keep what the user typed in, but still stay in the field and display an error
message. This might be suitable for larger texts, where the user just made a spelling mistake. It is better then to let
him correct what he typed than to let him enter it completely once again.

This can be achieved the following way:

- Return

True

in the

OnFieldChanging

event

- Return

False

in the

OnFieldDeactivating

event

The

OnFieldChanging

will determine that the user typed in something wrong, but accept the field anyway.

Thus, the field really gets the new value. The

OnFieldDeactivating

then will prevent the user from leaving the

field.

The fact that the field’s contents was wrong, must somehow be transported from the

OnFieldChanging

event to

the

OnFieldDeactivating

event: The

OnFieldDeactivating

cannot determine it on its own, because the

field’s contents already changed. The best way to do it is to add a

UserData

to the field:

Option Explicit
Dim WithEvents Field As FieldType

Private Sub Application_OnProjectLoaded(ByVal App As Application)
Set Field =
App.Project.DataSet.Schema.DocumentTypes("InvoiceTable").FieldTypes("TotalAmount")
End Sub

Private Function Field_OnFieldChanging(ByVal Field As Field, ByVal SubField As Field, _
ByVal VerifyEventArgs As VerifyEventArgs) As Boolean
Field_OnFieldChanging = True
'* reset old contents
If Field.UserData.HasValue("ErrorText") Then
Field.UserData.RemoveValue ("ErrorText")
End If

If Val(Field.Value) <= 0 Then
Field.UserData.Value("ErrorText") = "TotalAmount must be positiv"
End If
End Function

Private Function Field_OnFieldDeactivating(ByVal Field As Field, ByVal NextField As Field) As
Boolean
Field_OnFieldDeactivating = True

If Field.UserData.HasValue("ErrorText") Then
MsgBox Field.UserData.Value("ErrorText")
Field_OnFieldDeactivating = False
End If
End Function

Note that you cannot use the

OnFieldChanged

instead of the

OnFieldChanging

event for this purpose,

because this event will be fired after the

OnFieldDeactivating

!