Agile Tortoise

Greg Pierce’s blog

« Leo Hendrix Pierce      Goplan »

Servoy snippet: form_exists, form_method_exists

Here's a couple of useful Servoy methods I've been using...

To test for the existence of a form, use the following in a method (mine is in a mod_at module and named 'mod_at_form_exists'):

JavaScript:
  1. eval('forms.'+arguments[0]);
  2. return forms[arguments[0]] ? true : false;

Note the "eval" call ensures that the form has been loaded.

To test for the existence of a method on a form, use the following (i also keep this in a module, 'mod_at_form_method_exists'):

JavaScript:
  1. var frmName = arguments[0];
  2. var methodName = arguments[1];
  3.  
  4. if( !globals.mod_at_form_exists(frmName) )
  5.     return false;
  6.  
  7. return utils.stringLeft( typeof( forms[frmName][methodName] ), 7 ) == 'functio' ? true : false;

Note the last line is a workaround for Servoy's editor not allowing the keyword "function" to appear in a method (even in a string literal).

I use these methods to support abstracting form event methods using naming conventions and globals. I plan to post about that soon.

Monday, June 11th, 2007 at 6:38 am and is filed under Servoy. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Servoy snippet: form_exists, form_method_exists”

  1. Jason Says:
    August 13th, 2008 at 1:38 pm

    Thanks Greg. This really helped me out. I’m trying to create a generic navigation bar for record navigating and new/delete record kinda stuff. This was the trick that allowed me to check for a specific newRec method on each calling form, and if it doesn’t exist, I use currentcontroller.newRecord() instead. This allows me to put the nav bar anywhere and then have either a generic newRecord() or a custom one on the form, all with no code changes to the nav bar.

    Thanks!

Leave a Reply