I've been struggling with a navigation design that relies on a combination of Dialog List and Radio Button selections to populate various folders; the code is in the OnChange() event; when triggered, it finds the necessary documents, populates and displays the appropriate folder and tracks the current and previous selection values for each field.
The setup works but there are odd behaviours that I have not been able to isolate and track.
Yesterday I was searching notes.net for references to the OnChange() event and stumbled across the following:
Very important! The onChange event will run twice for every value change: once when the user changes the value, and again when the user leaves the field...
Ah Ha! Is that the source of my problem? Did some testing today and, sure enough, that is it. Or at least, a big part of what has been causing me headaches.
This is what happens, when the user makes a Radio Button selection and the fields 'Run Exiting/OnChange' is set and there is script in the OnChange() event:
Entering onChange Event->prevVal= (Length: 0)
Entering onChange Event->currVal= (Length: 0)
Exiting onChange Event->prevVal= (Length: 0)
Exiting onChange Event->currVal= Two(Length: 3)
----------------------------------------------
And here's what happens when the user exits the same field:
Entering onChange Event->prevVal= (Length: 0)
Entering onChange Event->currVal= Two(Length: 3)
Exiting onChange Event->prevVal= Two(Length: 3)
Exiting onChange Event->currVal= Two(Length: 3)
You can see that the
prevVal and
currVal variables end up being equal.
The script setting these values is executed twice!By contrast, using a DialogList which does not have the 'Run Exiting/OnChange' option but has script in the
OnChange() event:
Entering onChange Event->dlprevVal=
Entering onChange Event->dlcurrVal=
Exiting onChange Event->dlprevVal=
Exiting onChange Event->dlcurrVal= Cheyenne
The script in the
OnChange() event is executed only once; when the field is exited.
The workaround (for the Radio Button field) is to add a third variable, load it with the current selection and compare it to the saved current value; if they match, skip the code that sets current and previous values.
Dim ws As New NotesUIWorkspace
value$ = ws.CurrentDocument.FieldGetText("test1")
If(value$ <> currVal$) Then
prevVal$ = currVal$
currVal$ = value$
End If
I searched the help files for an explanation of what I'm seeing, this is the only entry I could find for
Run Exiting/OnChangeSpecial Notes Client Event Options (this section appears only for certain fields, including checkbox, radio button, list box, combobox, and time zone fields).
Run Exiting/OnChange events after value change - If you check this field, the OnChange event is triggered when the value in the field is changed.
If you leave this field unchecked, the OnChange event is not triggered unless the value in the field has changed and the focus has left the field.
I wish they had worded it a little better. I was under the impression that the event would be triggered immediately if the box was checked OR, if the box was unchecked, the event would be triggered when the field was exited. Not that the event would trigger
both times if the box was checked :(