Page 1 of 1

assign existing form method to form created at runtime

PostPosted: Sat Jan 05, 2013 9:36 pm
by sarar
I am creating a runtime form and want to use a method from an existing form in the onAction event of a button. I tried:
Code: Select all
_method = solutionModel.getForm(_formname).getMethod(_methodname)
_button = _jsForm.newButton("",_x,_y,_c_width_button,_height,_method)


I get the error: method must be a solution method, foundset method or forms own method

Is there a way to do this?

Re: assign existing form method to form created at runtime

PostPosted: Sat Jan 05, 2013 10:57 pm
by ROCLASI
Hi sarar,

I see this is your first post. Welcome to the Servoy forum :)

I assume you want to call a method from another form from your button?
Any event on a form (be it a form event or an event on a form element) can only be linked to it's own form method, global method or a foundset method (the foundset used on the form).
So if you try to link a method from another form to your custom button then this won't work.

As a workaround you can create a form method on your form that triggers the other form method like so:
Code: Select all
_method = _jsForm.newMethod("function() {forms['" + _formname + "']['" +_methodname + "'];}")
_button = _jsForm.newButton("",_x,_y,_c_width_button,_height,_method)


So as you can see the form method that is being created is calling your other form's method by code.

Hope this helps.
Don't hesitate to ask any questions if things are not clear.

Re: assign existing form method to form created at runtime

PostPosted: Sat Jan 05, 2013 11:42 pm
by sarar
Thanks for the welcome! took me a while to get the nerve up to post - I am a Servoy newbie.

The error is gone but the method is still not firing when I click the button. The debugger shows that the function aa is linked to onAction but the method is never called. BTW when I put the method in globals it works without issue.
Code: Select all
_method = _jsForm.newMethod("function aa() {forms['itemadd_dtl']['showmultipick'];}")
_button = _jsForm.newButton("",_x,_y,_c_width_button,_height,_method)

suggestions?

Re: assign existing form method to form created at runtime

PostPosted: Sun Jan 06, 2013 1:36 am
by ROCLASI
sarar wrote:Thanks for the welcome! took me a while to get the nerve up to post - I am a Servoy newbie.

We were all Servoy newbies once.
Just remember there are no stupid questions, only stupid answers. So I hope I don't give stupid answers. :)

sarar wrote:The error is gone but the method is still not firing when I click the button. The debugger shows that the function aa is linked to onAction but the method is never called. BTW when I put the method in globals it works without issue.
Code: Select all
_method = _jsForm.newMethod("function aa() {forms['itemadd_dtl']['showmultipick'];}")
_button = _jsForm.newButton("",_x,_y,_c_width_button,_height,_method)

suggestions?

Yes, I see I forgot to add some parenthesis in my example code (apart from not giving the function a name, which you already found out I see :) ).
forms['itemadd_dtl']['showmultipick'] will only give you the function object, it doesn't execute it. Adding () at the end will execute it.
So your code should be like this:
Code: Select all
_method = _jsForm.newMethod("function aa() {forms['itemadd_dtl']['showmultipick']();}")
_button = _jsForm.newButton("",_x,_y,_c_width_button,_height,_method)


Hope this helps.

Re: assign existing form method to form created at runtime

PostPosted: Sun Jan 06, 2013 4:31 pm
by sarar
Thanks much. It Worked