assign existing form method to form created at runtime

Questions, tips and tricks and techniques for scripting in Servoy

assign existing form method to form created at runtime

Postby sarar » Sat Jan 05, 2013 9:36 pm

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?
sarar
 
Posts: 14
Joined: Wed Nov 14, 2012 5:01 pm

Re: assign existing form method to form created at runtime

Postby ROCLASI » Sat Jan 05, 2013 10:57 pm

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: assign existing form method to form created at runtime

Postby sarar » Sat Jan 05, 2013 11:42 pm

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?
sarar
 
Posts: 14
Joined: Wed Nov 14, 2012 5:01 pm

Re: assign existing form method to form created at runtime

Postby ROCLASI » Sun Jan 06, 2013 1:36 am

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: assign existing form method to form created at runtime

Postby sarar » Sun Jan 06, 2013 4:31 pm

Thanks much. It Worked
sarar
 
Posts: 14
Joined: Wed Nov 14, 2012 5:01 pm


Return to Methods

Who is online

Users browsing this forum: No registered users and 12 guests