How to Create Validation and Selection Popups for Fields

ID: Q119230

2.5x 2.60 | 2.00 2.5x 2.60

WINDOWS   | MS-DOS

The information in this article applies to:

SUMMARY

While the list popup available in the Screen Builder is adequate for many purposes, it lacks a number of features that are available only through programming. The following examples demonstrate two forms of popups; the first is activated when the field is entered to allow selection of available values in a database, whereas the second is activated only after an invalid entry is made. Both popups allow the user to type in the first few letters to rapidly select a close match and then scroll up and down to select the exact item. After a selection is made, the remaining fields are filled in with the data from the selected record.

MORE INFORMATION

Functionality of the Popups

A key value created to uniquely identify a record (such as a customer number) is usually short and cryptic, which is ideal for use with an index and storage within a database. However, the cryptic nature of the key value poses a problem when the value must be entered in a screen input field in order to retrieve the matching record, as it becomes increasingly difficult for the user to remember what the codes represent when the number of different codes increases.

The two types of popups discussed below address this problem by presenting a list of valid choices that correspond to the codes (such as company names), rather than a list of valid codes.

The common code in both snippets performs the following actions:

The two commands following the ACTIVATE POPUP command undo the conditions set up before activating the popup and return the settings to their previous states.

The following steps use the TUTORIAL\CUSTOMER.DBF file to create a screen named POPLIST.SPR for editing existing records:

1. Close all databases, and then open the CUSTOMER.DBF database in the

   <FoxPro_directory>\TUTORIAL subdirectory.

2. Open a new screen in Screen Builder, and do one of the following:

    - Create a quick screen.

      -or-

    - Manually place any desired fields on a new screen.

      -or-

    - Modify an existing screen.

3. Open the Setup snippet, define the popup as shown below, and set an
   event trap (ON SELECTION) to deactivate the popup after a selection has
   been made.

   In this example, a variable named CUSTNO is created to hold the CNO key
   value so that it can't be changed accidentally:

      DEFINE POPUP cust FROM 1,15 PROMPT FIELDS company
      ON SELECTION POPUP cust DEACTIVATE POPUP
      custno=SPACE(5)

4. In the Screen Design window, double-click the CNO field and replace the
   "customer.cno" field expression name with "custno" (without the
   quotation marks). Then arrange the fields in the order of CUSTNO,
   CONTACT, COMPANY, with the remaining fields placed in whatever order is
   desired.

5. Open the Valid snippet of the CUSTNO field, and enter the following
   code:

      LOCATE FOR custno=customer.cno
      *** IF SEEK(custno) instead of LOCATE if an index on CNO is set.
      IF !FOUND()
          SET CONFIRM ON
       _DBLCLICK = 1.5
       ACTIVATE POPUP cust
       _DBLCLICK = .5
       SET CONFIRM OFF
      ENDIF
      custno=customer.cno
      SHOW GETS
      WAIT WINDOW 'Note changes...hit any key, then tab to Company'

6. Open the When snippet of the COMPANY field, and enter the following
   code:

      SET CONFIRM ON
      _DBLCLICK = 1.5
      ACTIVATE POPUP cust
      _DBLCLICK = .5
      SET CONFIRM OFF
      custno=customer.cno
      SHOW GETS

7. Save the changes and generate POPLIST.SPR.

Field Validation Popup

To demonstrate this type of popup, run POPLIST.SPR, and while in the CUSTNO field, press ENTER (or type a customer number that does not exist in the CUSTOMER database). The VALID clause attempts to locate a record whose customer number matches the CUSTNO value you typed. If a match is found, the record pointer is positioned on the matching record, and the SHOW GETS command updates the screen with the new values. If no match is found, the list of company names is presented. Type in the first few letters of a company name, then scroll down or up to select the desired record. Press ENTER, and then observe the new field values. The cursor should now be in the CONTACT field.

Auto-Activate Popup

To demonstrate this type of popup, run POPLIST.SPR, and press the TAB key to move from the CONTACT field to the COMPANY field. As soon as the cursor leaves the CONTACT field, the company name popup list is activated. Once the popup is open, its functionality is identical to that of the validation popup.

Additional reference words: FoxDos FoxWin 2.00 2.50a 2.50b 2.60 picklist getlist listbox list box pop-up pop up KBCategory: KBSubcategory: FxtoolSbuilder

Keywords          : kbcode FxtoolSbuilder 
Version           : 2.5x 2.60 | 2.00 2.5x 2.60
Platform          : MS-DOS WINDOWS

Last Reviewed: May 22, 1998