Detecting data modification immediately

This section describes the purpose of the predefined dialogtouched action. Consider also using the ON CHANGE trigger when the form item type allows to detect value changes immediately, for example in COMBOBOX and CHECKBOX fields.

Singular interactive instruction are typically ended with an accept or cancel action. For example, a singular INPUT statement allows the end user to enter a database record, and validate or cancel the input for that record. The INPUT statement is then re-executed to input another record.

Unlike singular dialogs, the DIALOG instruction can be used continuously for several data operations, such as navigation, creation, or modification. Typically, default is the navigation mode, and as soon as the user starts to modify a field, it switches to edit mode, to modify a record, or create a new record.

In such case, the dialog must be notified when the user starts to modify the current record, for example to enable a save action. This is achieved with the dialogtouched predefined action. When a ON ACTION dialogtouched action handler is defined, the front-end knows that it must send this action when the end-user modifies the current field (without leaving that field), just by a simple keystroke.

The dialogtouched action must be enabled/disabled in accordance with the status of the dialog: If this action is enabled, the ON ACTION dialogtouched block will be invoked each time the user types characters (or modifies the value with copy/paste) in the current field; As this can generate a lot of network traffic, the action must be disabled as soon as it is detected, and the dialog can then enter in modification/edit mode. After the user triggers the save action to commit the changes, the dialogtouched action can be re-enabled. To enable/disable actions, use the DIALOG.setActionActive() method.

This programming pattern is illustrated by the next code example:

DIALOG
   ...
   ON ACTION dialogtouched 
      CALL setup_dialog(DIALOG,TRUE)
   ...
   ON ACTION save 
      CALL save_record()
      CALL setup_dialog(DIALOG,FALSE)
   ...
END DIALOG
 
FUNCTION setup_dialog(d,editing)
   DEFINE d ui.Dialog, editing BOOLEAN
    CALL DIALOG.setActionActive("dialogtouched", NOT editing)
    CALL DIALOG.setActionActive("save", editing)
    CALL DIALOG.setActionActive("query", NOT editing)
END FUNCTION