mardi 18 septembre 2012

How to override the event methods on dialog controls?


Overriding the event methods (e.g. modify, validate, selectionChange) on dialog controls is not as straight forward as it is on form controls, but the good news is that it is possible!
In order to override the event methods on dialog controls, the following needs to be done (for simplicity we assume that your class extends RunBase class) :
1) The method dialogPostRun() should be overridden and following two lines are added after the super() call:
_dialog.dialogForm().formRun().controlMethodOverload(true);
_dialog.dialogForm().formRun().controlMethodOverloadObject(this);

This will allow to call the event methods of your class.

2) The actual event methods should be added.
The format of the event method name is as follows: fld<ID>_1_<event name>

Please see the example below.
This method is called whenever a value of the dialog control with ID 900 is modified. In our case it is Employee ID field.

public boolean fld900_1_modified()
{
FormStringControl control = dialog.formRun().controlCallingMethod();
boolean isFieldModified;
;
isFieldModified = control.modified();
// every time the employee id is changed, update the employee name
if(isFieldModified)
{
dlgFldEmplName.value(EmplTable::find(control.text()).Name);
}
return isFieldModified;
}
You will also need to make sure that the control “Employee ID” gets the same control ID as used in the event method name (ID 900). This should be done at the time of adding the control to the dialog. Please see below:
protected Object dialog(DialogRunbase _dialog, boolean _forceOnClient)
{
;
dialog = super(_dialog, _forceOnClient);
// Add a new field by explicitly specifying the field id.
// This field id is used to create the field event methods (e.g. fld900_1_modified()).

dlgFldEmplId = new DialogField(dialog, typeid(EmplId), #dlgFlgEmplIdFieldNo);
dialog.addCtrlDialogField(dlgFldEmplId.name());
dlgFldEmplId.init(dialog);
dlgFldEmplId.label("@SYS81251");
dlgFldEmplId.helpText("@SYS81251");
dlgFldEmplId.value(emplId);

}
As you can see the macro #dlgFlgEmplIdFieldNo is used to assign the ID to the dialog control. The macro is defined in the classDeclaration and it equals 900.

Aucun commentaire:

Enregistrer un commentaire