I believe that at least once you had a task where you had to apply the same logic to many similar fields in a single table column.
For instance, when user enters something into a field then on Exiting/onChange event you want to take this value and do some manipulations and you want to implement this logic for all fields in this table column.
Usually all fields have similar names and they differ only by indexes which represent row numbers.
Lotusscript provides you with capability to get a name of a current field using NotesUIDocument.CurrentField property. However, you cannot use this property on Exiting/onChange event because this property refers to where the cursor goes, not to the field being exited.
So you have to provide a field index (row number) manually for every handler of every Exiting/onChange field event and this is a boring work and takes a time.
I believe that a good developer should be a lazy developer (in a right sense, of course). I personally did it the same way before but today I got the same task and this time I decided to avoid explicit definition of field index (row number) and find a better way.
So, here it is :-)
The solution is very simple actually:
1) You have to add an additional editable field on your form, f.x. currentfield
2) Then you have to two options:
- you may add JavaScript code
document.forms[0].currentfield.value = this.name;
into onFocus event of all required fields: - you may add Lotusscript code
Dim w as new notesuiworkspace
w.currentdocument.document.currentfield = w.currentdocument.currentField into onFocus/Entering event of all required fields
I personally prefer option 2.1.
Be sure that you select option "Client" for your JavaScript if you choose it also.
Actually, that's it.
When you set cursor into any field in your table this code writes current field name into the "currentfield" field, so on Exiting/onChange event you can use some common sub/function that will figure out where it works using a value of the "currentfield" field.
No comments:
Post a Comment