Move to Next Control on ENTER
Description
This script shows a simple method that advances the cursor to the next field on a form when the user clicks ENTER. This is a simple Xdialog with multiple text fields.
dim dlg_title as C dlg_title = "Advance on Enter" dim fn as C dim ln as C dim address1 as C dim address2 as C dim city as C dim st as C dim zip as C ui_dlg_box(dlg_title,<<%dlg% {on_key=enter} Press Enter to advance to next field. When focus is on OK button, Enter will close the dialog; {lf}; {frame=1,1} {region} First name: | [.50fn]; Last name: | [.50ln]; Address 1: | [.50address1]; Address 2: | [.50address2]; City: | [.50city]; State: | [.5st]; Zip: | [.10zip]; {endregion}; {lf}; {justify=right}
Note how the OK button's event is clearly defined and different from any other event generated by the script.
<10&OK!ok> <10&Cancel!cancel>;
Now, after testing to see whether the ENTER button was pressed, the script uses UI_DLG_CTL_CURRENT()to examine the code executed by the button to see whether OK button was pressed.
%dlg%,<<%code% if a_dlg_button = "enter" then if atc("!ok", ui_dlg_ctl_current(dlg_title)) > 0 then 'user is on the OK button, so close the dialog
Since the code for the button pressed does include the string "!ok", you know that the user has not clicked the 'X' button to close the dialog. The script now uses UI_DLG_NAVIGATE()to move to the next control.
else 'user is not on the OK button, so advance to next control ui_dlg_navigate(dlg_title,"Next") 'set a_dlg_button to NULL to keep the dialog open a_dlg_button = "" end if end if %code%)
Limitations
Desktop applications only
See Also