Custom field event?

Hi,

Is it possible to write a custom event handler for a field on a form?

I have tried something like this, but only get an error that says “Not a product class instance: FIELD”

Sub Initialize

Dim s as new NotesSession

Dim form As NotesForm

Set form = s.CurrentDatabase.GetForm( “myForm” )

Forall field In form.Fields

If field = "myField" Then 

  On Event OnChange From field Call myOnChangeHandler

End If

End Forall

End Sub

Any help would be very much appreciated.

Kind regards

Jens

Subject: RE: Custom field event?

Read the documentation of the properties you are using. NotesForm.Fields returns an array of strings. Naturally you can’t register an OnChange event against a string.

There is no LotusScript object corresponding to a field, so you can’t register an event against it. In any case, even if there were such an object, it would need to be a UI object (like NotesUIDocument) for you to mess with its events at runtime. I’m not sure whether this would even work for a NotesUIDocument’s events. I guess you could try it.

If you spell out your requirements, people could probably suggest another way to do what you’re trying to do.

Subject: RE: Custom field event?

Yes I know, it came to my attention and struck me as a sledge hammer just after I had pressed the submit button “DANG What a silly question to ask” -but lesson learned, always read the documentation thoroughly before asking question. But after having turn the problem over in my mind a couple of times more I came up with this solution. I know it is not optimal, but it can be used.

I have briefly outlined the solution below (this is not the final code).

Create a new public class in the Script library ( or where you may find it suitable)

Public Class FieldEventHandler

Sub new(arg As Field)

On Event Onchange From arg Call OnChangeHndl

'… register as many event as necessary

End Sub

Sub OnChangeHndl(Source As Field)

'… Do whatever needed!

End Sub

End Class

In the field event “Entering” place the following code,

Sub Entering(Source As Field)

Dim evntHndl As New FieldEventHandler(Source)

End Sub

A more optimal solution would be to take a document and then register all the events that needed to be handled. The rationale behind all this is to aim for a better way to maintain a common code base. So instead of maintaining code in many different places like in forms, fields, etc. It’s now all gathered in a shared Script library. This also makes sense in a perspective of reusable code.

regards

Jens