There are some methods I’d like to have available for all forms within a particular table. I’ve been duplicating, one by one, a set attached to one of the existing forms. Later I’ll begin attaching them to particular fields, buttons, onShow, onHide etc.
By working this way is there a feature or coding strategy I’m missing?
I’d far prefer having a single set of methods attached to the table in much the same way as global methods are attached to all forms throughout the solution. With table methods any change made would apply to all instances they’re called throughout that table. I’d not have to remember to change each of the methods on each of the forms within that table.
Just make a global “onShow” method and attach to all the applicable forms.
For example: “onShow_Customer” - you can attach that to all forms based on the customer table, etc.
Is that what you meant?
Bob Cusick
Not really. I’m including the same portals on several forms of one particular table. Many of the fields on these portals call for methods for onFocusGained and/or onFocusLost, onAction, and so forth. Unlikely to be used on the forms of any other table.
Therefore I’m currently duplicating these same set of methods from one form to the next to the next. While doing this I noticed an error in one of these methods. Which meant going back and fixing all the other copies. Shades of FMP.
Sounds like there’s no more efficient way of handling this than the way I’m doing it.
If you need different functionality for each field on each form, then you DO have to create separate methods. HOWEVER, you can take the parts of the methods that are the SAME and make a single global method and call it. For example, say you wanted to show a dialog when there was an error. Rather than placing this code:
plugins.dialogs.showErrorDialog( 'Error', 'Sorry, an error happened.', 'OK')
in EVERY method - you can make a GLOBAL method called “dialog_error” and CALL that method from other methods. For example:
if(field1 != field2)
{
globals.dialog_error
}
AND - to get more “fancy” - every method in JavaScript can pass and accept arguments. So, if you wanted to display a custom message - you can change the code for dialog_error to:
plugins.dialogs.showErrorDialog( 'Error', 'Sorry, an error happened: ' + arguments[0], 'OK')
The “arguments[0]” part will display the first parameter that’s passed. Now we change the code in our triggering method to:
If you do this - you can keep all the “common” code in global methods that you can call from anywhere and reduce the number of “places” you have to update code.