How to get currently active form?

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

How to get currently active form?

Postby roddy » Thu Nov 26, 2020 8:13 am

When a form has child forms inside, how do I determine which of the forms is currently the active one? application.getMethodTriggerFormName() has been deprecated in favour of JSEvent and most responses on the forum refer to this.

The JSEvent from a button to move the record select is in the nav bar, so the event just has the name of the nav bar form; I keep the current parent form in a separate global variable, so I can access that but I cannot figure out how to determine which of the tab panels in the form is currently active. I feel there must be a simple way of getting the form that has focus with a current record selection.

Any help would be much appreciated.
roddy
 
Posts: 100
Joined: Mon Oct 26, 2020 12:32 am

Re: How to get currently active form?

Postby swingman » Thu Nov 26, 2020 10:36 am

Hi Roddy,

I use the following to keep track, see if it will work for you:

Code: Select all
function current_screen() {
   return application.getActiveWindow().controller.getName();
}
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1472
Joined: Wed Oct 01, 2003 10:20 am
Location: London

Re: How to get currently active form?

Postby ROCLASI » Thu Nov 26, 2020 11:39 am

Hi Roddy,

The controller has a function getFormContext() that gives you a dataset with the complete hierarchy of the nested forms, including the tabpanel names and tab indexes (0 and 1 based).
Code: Select all
var _dsContext = controller.getFormContext();
// for a quick output of the dataset. The top most form is the first record.
application.output(_dsContext.getAsText(",", "\n", "", true));


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: How to get currently active form?

Postby roddy » Fri Nov 27, 2020 2:28 am

Thanks Swingman and ROCLASI; I really appreciate the responses.

Code: Select all
application.getActiveWindow().controller.getName();

provides the name of the navigation form (using svyNavigation), unfortunately.

Code: Select all
controller.getFormContext()

{rowColumns:["windowname","formname","containername","tabname","tabindex","tabindex1based"],rowIndex:-1,row_1:[(1) windowname:"1",(2) formname:"frm_nav_main",(3) containername:"sidenav",(4) tabname:null,(5) tabindex:0,(6) tabindex1based:1],row_2:[(1) windowname:"1",(2) formname:"parent",(3) containername:null,(4) tabname:null,(5) tabindex:null,(6) tabindex1based:null]}

provides the window and the forms, all the way down to the parent form but not the tabs within it.

I've decided to go down the route of specifying any sub-forms to determine which is affected by the record navigation, as opposed to determining a generic rule.
roddy
 
Posts: 100
Joined: Mon Oct 26, 2020 12:32 am

Re: How to get currently active form?

Postby roddy » Fri Nov 27, 2020 5:34 am

As an FYI, I am using the function:
Code: Select all
getSelectedTabFormName()

Which can be accessed from the element holding the multiple tab panels.
roddy
 
Posts: 100
Joined: Mon Oct 26, 2020 12:32 am

Re: How to get currently active form?

Postby swingman » Fri Nov 27, 2020 10:57 am

Hi Roddy,

Code: Select all
provides the name of the navigation form (using svyNavigation), unfortunately.


Right, if every form is nested inside a navigation form my code will not work. I use my own navigation with one base form for each data type (client, invoice, project, etc)
I found with the Smart Client that putting the whole app inside one form led to bad performance because Servoy loaded too much stuff into memory.
The NG-Client may be a lot smarter so this is no longer an issue.
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1472
Joined: Wed Oct 01, 2003 10:20 am
Location: London


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 7 guests

cron