Page 1 of 1

Method on the fly

PostPosted: Thu Jul 05, 2012 8:33 am
by DEK4
Hello!

I have a problem... i try to create a new method with newMethod() and it doesn't work..

Code: Select all
_method = globals._dynamicForm.newMethod('function _nextStep_' + globals.getUUID() + '() { application.output("Method _nextStep"); }')
_button = globals._dynamicForm.newButton('Continua >',0+_marginLeftDTL,globals._hRowDTL*_currentRowDTL,globals._wColumnLabelDTL+globals._wColumnDataDTL,globals._hRowDTL*2,_method)
_button.onAction = _method;
_button.name = "_nextStep_" + globals.getUUID()
_button.enabled = true


thanks

Re: Method on the fly

PostPosted: Thu Jul 05, 2012 9:35 am
by ROCLASI
Hi,

You are using a UUID in the method name. This UUID has hyphens (-) in there and those are not supported in a function name so you should strip them out.
In fact hyphens are not really supported in any object name.

Try the following code instead:
Code: Select all
_method = globals._dynamicForm.newMethod('function _nextStep_' + utils.stringReplace(globals.getUUID(), "-","") + '() { application.output("Method _nextStep"); }')
_button = globals._dynamicForm.newButton('Continua >',0+_marginLeftDTL,globals._hRowDTL*_currentRowDTL,globals._wColumnLabelDTL+globals._wColumnDataDTL,globals._hRowDTL*2,_method)
_button.onAction = _method;
_button.name = "_nextStep_" + utils.stringReplace(globals.getUUID(), "-","")
_button.enabled = true


Hope this helps.

Re: Method on the fly

PostPosted: Thu Jul 05, 2012 10:18 am
by DEK4
Hi, thanks for your answer...but it doesn't work...

i try also without the getUUID but nothing...

Re: Method on the fly

PostPosted: Thu Jul 05, 2012 11:41 am
by Joas
Did you call controller.recreateUI() on your changed form?

Re: Method on the fly

PostPosted: Thu Jul 05, 2012 12:34 pm
by DEK4
Yes but nothing......

Code: Select all
_method = globals._dynamicForm.newMethod('function aMethod(event){application.output("Hello world!");}');
_button = globals._dynamicForm.newButton('Continua >',0+_marginLeftDTL,globals._hRowDTL*_currentRowDTL,globals._wColumnLabelDTL+globals._wColumnDataDTL,globals._hRowDTL*2,_method)
_button.onAction = _method;
_button.name = "_nextStep_" + utils.stringReplace(globals.getUUID(), "-","")
_button.enabled = true
controller.recreateUI()
return false

Re: Method on the fly

PostPosted: Thu Jul 05, 2012 1:29 pm
by ROCLASI
Hi,

What exactly doesn't work ?
The button doesn't show up ? Or clicking the button doesn't seem to trigger the method, i.e. you don't see the application.output ?

Re: Method on the fly

PostPosted: Thu Jul 05, 2012 3:15 pm
by omar
Hi,

I simplified your example and was able to reproduce your problem when the global form var did not contain a valid object. Like this it works:

Code: Select all
   if (!globals._dynamicForm) {
      globals._dynamicForm = solutionModel.getForm('frmWhatEver');
   }
   var method = globals._dynamicForm.newMethod('function myMethod(event) { plugins.dialogs.showInfoDialog("Test","Hello World");}');
   servoyDeveloper.save(globals._dynamicForm);
   var button = globals._dynamicForm.newButton('Hello World',250,250,80,20,method);
   button.name = 'myNewButton';
   currentcontroller.recreateUI();


Perhaps the assumption that globals.dynamicForm is filled is mistaken?