Ask Reuben
INFIELD
How can I disable an action when the focus is not in a field?
How can I perform a different function for an action based on the current field?
The INFIELD attribute was added in Genero 2.20 but it is still surprising how much code I have seen that does not take advantage of it. A reminder that every time there is a new Genero version, we list the new features in the documentation. I would consider it good practise to periodically review your code base to take advantage of these new features.
The INFIELD (or field-specific actions INFIELD clause) says that an ACTION is only active if the focus is in a certain field. This means you can code …
ON ACTION action-name INFIELD field-name ...
Prior to 2.20 this would require code of this nature …
BEFORE INPUT -- or construct or dialog CALL DIALOG.setActionActive("action-name", FALSE) BEFORE FIELD field-name CALL DIALOG.setActionActive("action-name", TRUE) AFTER FIELD field-name CALL DIALOG.setActionActive("action-name", FALSE) ON ACTION action-name ...
The other advantage of the INFIELD clause is that you no longer need to determine what field you are in. You know it based on the fact the action will only be triggered if you are in that field. This is typically seen with lookup/zoom windows where you can now code …
ON ACTION action-name INFIELD field1-name LET field1-name = zoom_field1-name() ON ACTION action-name INFIELD field2-name LET field2-name = zoom_field2-name()
… as opposed to coding …
ON ACTION action-name CASE FGL_DIALOG_GETFIELDNAME() WHEN "field1-name" LET field1-name = zoom_field1-name() WHEN "field2-name" LET field2-name = zoom_field2-name() OTHERWISE -- handle case if action triggered for some other field
There is one other thing to note with INFIELD. When it was originally implemented, the action-name attached to a BUTTONEDIT had to be a field-qualified action. With 3.10 we relaxed that and you can code …
BUTTONEDIT f01 = formonly.field-name, ACTION=action-name, ...;
… as opposed to the more correct but less intuitive…
BUTTONEDIT f01 = formonly.field-name, ACTION=field-name.action-name, ...;
What this and the ON ACTION action-name INFIELD field-name
achieves is that the BUTTONEDIT button is active even though the focus is not in the field. The clicking of the BUTTONEDIT button moves the focus to the field and then triggers the actions which is what the user is expecting. The user is not expecting to have to click in the field to make it the field with focus and then for the button to be made active and for them to then click in it.
The INFIELD clause is an example of something we have added to the language that benefits your application and improves the code base. I would always encourage you to participate in early access programs and give feedback to new syntax. Then when the release occurs you are in position to transform your sources to use this new syntax.