Form field deactivation
The form fields bound to a dialog are by default active (i.e. they can get the focus). When
needed, disable the fields that do not require user input, and reactivate them later
during the dialog execution. For example, imagine a form containing an "Industry"
COMBOBOX
field , with the options Healthcare,
Education, Government, Manufacturing, and Other . If the
user selects "Other", a secondary EDIT
field is expected to be
activated automatically, to let the user input the specific description of the industry.
But if one of the predefined values is selected, there is no need for the additional
field, so the secondary field can be left disabled.
ui.Dialog.setFieldActive()
method depending on the context. The "Industry" field
case described can be implemented as
follows:DIALOG ATTRIBUTES(UNBUFFERED)
INPUT BY NAME rec.*
ON CHANGE industry
-- A value of 99 corresponds to the "Other" item
CALL DIALOG.setFieldActive( "cust.industry", (rec.industry!=99) )
...
END INPUT
BEFORE DIALOG
CALL DIALOG.setFieldActive( "cust.industry", FALSE )
...
END DIALOG
Consider centralizing field activation / deactivation in a setup function specific to the dialog,
passing the DIALOG
object as parameter.
Do not disable all fields of a dialog, otherwise the dialog execution stops (at least one field must get the focus during a dialog execution).
If you disable the current field having the focus, the dialog will execute the AFTER
FIELD
block of the current field and the BEFORE FIELD
block on the next field in the tabbing order. This can unnecessarily fire validation
code implemented in AFTER FIELD
. As a general pattern, it is not
recommended to disable a field in your dialog code when it is not the current field.
It is also possible to hide fields with the ui.Form.setFieldHidden()
method of
the form objects. The dialog considers hidden fields as disabled (there is no need to
disable fields that are already hidden). But hiding form elements changes the space used
in the window layout and the form may be displayed in an unexpected way. When hiding
elements in containers prepared for that, such as tables, this doesn't happen.