Calling forms with parameters

Questions and answers for designing and implementing forms in Servoy

Calling forms with parameters

Postby fgsmartest » Mon Jun 25, 2012 5:17 pm

Hi, I want to call a form but would like to send its data source and columns to display to it as parameters so that it can then be set at "on show". how can i do that? help plz.
fgsmartest
 
Posts: 38
Joined: Thu Apr 12, 2012 12:40 am

Re: Calling forms with parameters

Postby ptalbot » Mon Jun 25, 2012 5:28 pm

You cannot set a datasource in the onShow of a form. You need to set it (from the solutionModel) before the form is loaded...
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Calling forms with parameters

Postby omar » Tue Jun 26, 2012 1:27 pm

Are you by any chance a developer with a Visual FoxPro background? What you have to realize is that all forms are initialized at application startup and are shown or hidden instead of initialized and destroyed. If you want you can create a form from scratch and do whatever you like. This for example is a BROWSE function that will create a BROWSE like form for any dataset that you feed it.

Code: Select all
function browse(ds) {
   // create an in memory dataSource
   var tmpDataSource = ds.createDataSource('temp');
   // create a form
   var frmBrowse = solutionModel.newForm('Browse',tmpDataSource,null,true,460,600);
   frmBrowse.view = JSForm.LOCKED_TABLE_VIEW;
   // add fields
   var fieldPos = 0;
   for (var i = 1; i <= ds.getMaxColumnIndex(); i++)
   {
      // get column name
      var colName = ds.getColumnName(i)
      // determine column width
      var colArray = ds.getColumnAsArray(i);
      var colWidth=50
      for (item in colArray) {
         colWidth = Math.max(colWidth,colArray[item].length*10);
      }
      if (colWidth > 250) {
         colWidth=250;
      }
      // add column
      var fld = frmBrowse.newTextField(colName,fieldPos,0,colWidth,20);
      fld.titleText = colName;
      // determine next field position
      fieldPos = fieldPos + colWidth;
   }
   // show form as a modal popup
   var win = application.createWindow("BrowseWindow", JSWindow.MODAL_DIALOG);
   forms['Browse'].controller.show(win);
   // cleanup
   solutionModel.removeForm('Browse');
}

function test() {
   var ds = databaseManager.createEmptyDataSet();
   ds.addColumn('country_id');
   ds.addColumn('country_code');
   ds.addColumn('country_name');
   ds.addColumn('country_english');
   // add data
   ds.addRow([31, 'NL', 'Nederland', 'The Netherlands']);
   ds.addRow([32, 'B', 'België', 'Belgium']);
   ds.addRow([33, 'F', 'France', 'France']);
   ds.addRow([49, 'D', 'Deutschland', 'Germany']);
   globals.browse(ds);
}
Intrasoft, Founder
Omar van Galen
omar@intrasoft.nl
+31-(0)6-21234586
Servoy Developer
omar
 
Posts: 377
Joined: Sat Feb 12, 2011 4:51 pm
Location: Intrasoft, The Netherlands

Re: Calling forms with parameters

Postby fgsmartest » Thu Jun 28, 2012 10:20 pm

thanks, very interesting idea! Didnt think of doing it this way.
fgsmartest
 
Posts: 38
Joined: Thu Apr 12, 2012 12:40 am


Return to Forms

Who is online

Users browsing this forum: No registered users and 7 guests