Tips_gui   >   Windows   >   Entry Fields

Entry Fields

This section includes various tips and demos on text entry fields.

$cobj.$contents

Think of the field $contents as a keyboard buffer which gets written into the $dataname variable when focus leaves the field.

Each entry field has a $dataname property. The $dataname points the entry field to a variable which stores the value that the entry field displays.

The $dataname value is loaded into the $contents when the field is redrawn or when the field becomes the current field (On evBefore).

As the user types keys on the keyboard, the $contents value changes, but not the $dataname value.

When the focus leaves the entry field (On evAfter), the $contents value is copied to the $dataname variable.

A situation where you might watch the $contents is in a window where you ask the user to re-enter a new password and want to enable an Okay button as soon as the user matches the the previously entered new password.

; $event method for 're-enter password' field.

On evKey

; Allow the keystroke to be processed.
Process event and continue

; Enable/disable the Okay button based on whether or not
; it matches the new password in the previous field.
Do irOkayButton.$enabled($cobj.$contents=iNewPassword)

A situation where you want to manually copy the $contents to the $dataname is when an entry field has a context menu. The context menu event occurs without an evAfter event. When focus returns to the entry field an evBefore reloads the $contents from the $dataname wiping out any changes the user may have made prior to opening the context menu. The following sample $event method code shows how to copy the $contents to the $dataname before opening the context menu.

; $event method

On evOpenContextMenu

; Copy the entry field $content to the $dataname
Calculate [$cobj.$dataname] as $cobj.$contents

; Continue with opening the context menu.
Process event and continue

$firstsel & $lastsel

In my applications I have entry fields which I classify as click-edit fields. These fields are enabled in new mode but intially disabled in edit mode because the field values normally aren't changed after the record has been inserted. e.g. FirstName and LastName.

When the user clicks on a click-edit field, I enable the field and select all of the text in the field, just as though they had tabbed into the field.

The following $event method code shows how this is done.

On evClick

; Enable the field, set the focus, set the color.
Do $cobj.$enabled.$assign(kTrue)
Do $ctarget.$assign($cobj)
Do $cobj.$forecolor.$assign(kWhite)

; Select all of the text in the field.
Do $cobj.$lastsel.$assign(10000)
Do $cobj.$firstsel.$assign(0)

On evAfter

; Disable the field, set the color.
Process event and continue
Do $cobj.$enabled.$assign(kFalse)
Do $cobj.$forecolor.$assign(rgb(255,255,153))

Note

You can put this code in the $control window class method and then be sure to pass the events from the entry field to the next handler.

Calculated Entry Fields

If you want to have a calculated display entry field in a window or a complex grid there are 2 entry field properties which you need to set:

You can then enter your calculation in the $text property of the entry field, or you can assign the $text property of the field from a method.

If you don't set both properties, Omnis Studio will not display your $text calculation or value.

Click Run Demo to see a calculated entry field being used in window field and a complex grid.

Enter key = Tab key

You can change the behaviour of the Enter key to equal the behaviour of the Tab key. If your application has a lot of numeric data entry your users will appreciate this simple user interface change, and your boss will appreciate the increased productivity.

In my application we have windows for Timesheet entry, Purchase Order entry, Inventory Disbursements, Accounts Payable Invoice entry, Accounts Receivable Invoice entry. All of these tasks make heavy use of the numeric keypad. You would be amazed at the time saved when the user can use the Enter key on the numeric keypad to move from field to field, rather than reach for the Tab key. In our application time sheet entry input increased 30% by this simple change.

Many of the old green screen systems used the Enter key to move from field to field.

The code for doing this is extremely simple.

; Method: $control - of your superclass window class.
On evKey

; Intercept Enter key event, replace with Tab event.
If pSystemKey=kEnter
   If #SHIFT ;; kEnter
      Queue tab (Shift) ;; Do a shift tab instead
   Else
      Queue tab ;; Do a tab instead
   End If
   Quit event handler (Discard event) ;; Discard the enter key event
End If

I recommend putting this code in the $control method of your superclass window. You must make sure that $keyevents is set to kTrue in the properties of all your libraries.

If you have an On evKey in the $event method in any entry fields you must end include Quit event handler (Pass to next handler) in order to pass the event to the $control method.

Keyboard events, evKey

You can trap keyboard events with On evKey in the $event field method. (or the window $control method if the event is passed to that level.)

The evKey event is sent to the $event method with the parameters pKey and pSystemKey.

Tab and Shift+Tab have their own event codes, evTab and evShiftTab. You can (and should) trap On evTab and On evShiftTab rather than their system key equivalents for easier to read code.

In your application make sure $keyevents is set to kTrue in your library properties or the object properties.

Click the Run Demo button in the StudioTips Browser for this topic to find out the values of pKey and pSystemKey for various keys.

Multi-line Entry Field Height

If you have a multi-line entry field that has 2378 characters and random carriage returns, how do you figure out the height of the text in the field?

Tech Support once sent me a library which included some code for figuring out the height of the text in a multi-line entry field. The code worked but the notation is so unconventional that I assume this must be an undocumented feature.

I use this trick for setting the height tip description field in the StudioTips Browser window.

Here is the code:

; "rField" is an item reference variable referencing a multi-line entry field.
; The field is displaying some text.

; rField.$add(21) returns the number of lines in the multi-line field. (Undocumented feature)
Calculate LineCount as rField.$add(21)

; Assign the negative of the linecount to the $height correctly sets the multi-line field height. (Undocumented feature)
Do rField.$height.$assign(-LineCount)

; If you wanted to accomplish the above in a single line of code. :-)
Do rField.$height.$assign(-rField.$add(21))

Click the Run Demo button to test the code.

Tab and Shift+Tab Events

If you tab or shift+tab out of a field, Omnis Studio sends an evTab or evShiftTab $event message to the field. You can trap these tab key related events with On evTab and On evShiftTab in the $event method of the field.

Type Ahead Combo Droplist

Many of the popular software programs (Outlook Express, Quicken,...) try to finish data entry for the user by finding matching entries and adding the text from the first match to the field while the user is typing. I call this behavior type-ahead.

The kCombo field allows you to build a droplist which the user can select, but it doesn't handle type-ahead in the same way as you experience it in Quicken or Outlook.

You can combine a kEntry field and a kCombo field to obtain type-ahead behavior.

Click the Run Demo button in the StudioTips Browser to try out the type-ahead demonstration.

The code in the demo window is in the field $event methods and is well commented.