onFocusGained in a runtime created form

Questions, tips and tricks and techniques for scripting in Servoy

onFocusGained in a runtime created form

Postby studiomiazzo » Tue Nov 04, 2014 10:30 am

If I dynamically create a form with the solutionModel, I can't get the onFocusGained and onFocusLost methods work on a field element. The weird thing is that the onAction and onDataChange methods bounded to the same field element instead work correctly. Have anybody faced the same problem? I'm using Servoy 7.4.1 but I've also tried in 7.4.2 and in the previous release with the same result.

Here's a example of my code returning the form created :

Code: Select all
   var tForm = solutionModel.newForm(formName, globals.Server.MA_PRESENZE, globals.Table.STORICO, 'leaf_style', false, 360, 150);
      tForm.extendsForm = solutionModel.getForm(forms.svy_nav_base.controller.getName());
      tForm.navigator = SM_DEFAULTS.NONE;
      tForm.view = JSForm.RECORD_VIEW;
      tForm.scrollbars = SM_SCROLLBAR.HORIZONTAL_SCROLLBAR_NEVER | SM_SCROLLBAR.VERTICAL_SCROLLBAR_NEVER;
      tForm.transparent = true;
   
   /** @type JSLabel */
   var tLabel
   /** @type JSField */
   var tField
   /** @type {JSVariable} */
   var tVariable;
   
   var topMargin = 0;
   var sideMargin = 10;
   
   var fldHeight = 20;
   var fldLength = 80;
   var lblHeight = 20;
   var lblLength = 170;
   
   var xLLeft = sideMargin;
   var xLRight = tForm.width - sideMargin - lblLength;//Math.floor(tForm.width / 2) + xLLeft;
   
   var dy = lblHeight + fldHeight;   

   var fieldType;
   var fieldStyle = 'default';
   var fieldFormat = '';
   var fieldAlignment = SM_ALIGNMENT.CENTER;
   var fieldsNo = 10;   
   for (var i = 1; i <= fieldsNo; i++)
   {
      var dataType = globals.DataType.DATETIME;
      var variableType = = JSVariable.DATETIME;
      tVariable = tForm.newVariable('v' + currField.codice, variableType);
      var row = Math.floor((i - 1) / 2);
      
      tField.name =  currField.codice;
      tField.styleClass = fieldStyle;
      tField.format = fieldFormat;
      tField.horizontalAlignment = fieldAlignment;
      tField.transparent = transparent;
      tField.tabSeq = i;
      
      
      tField.onDataChange = solutionModel.getGlobalMethod('globals','onFocusGainedLost');
      tField.onAction = solutionModel.getGlobalMethod('globals','onActionFocusGainedLost');

                tField.onFocusGained = solutionModel.getGlobalMethod('globals','onFocusGained');
      tField.onFocusLost = solutionModel.getGlobalMethod('globals','onFocusLost');
      
   }
   
   return tForm;
}


Thanks in advance for any help.
User avatar
studiomiazzo
 
Posts: 124
Joined: Thu Jun 16, 2011 10:48 am
Location: Novara (IT)

Re: onFocusGained in a runtime created form

Postby jcompagner » Mon Nov 24, 2014 7:03 pm

that should work fine, are you sure you are attaching a good global method?

There should not be any difference, so you add the same exact method to onaction,ondatachange and the 2 onfocus
then focus is never called?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: onFocusGained in a runtime created form

Postby studiomiazzo » Tue Nov 25, 2014 10:02 am

Sorry, I'll try to explain with a more understandable code, imagine we have :
Code: Select all
      tField.onDataChange = solutionModel.getGlobalMethod('globals','testMethod');
      tField.onAction = solutionModel.getGlobalMethod('globals','testMethod');

      tField.onFocusGained = solutionModel.getGlobalMethod('globals','testMethod');
      tField.onFocusLost = solutionModel.getGlobalMethod('globals','testMethod');


Function testMethod is reached on the onAction and onDataChange but is never reached due to gained or lost focus.
User avatar
studiomiazzo
 
Posts: 124
Joined: Thu Jun 16, 2011 10:48 am
Location: Novara (IT)

Re: onFocusGained in a runtime created form

Postby jcompagner » Tue Nov 25, 2014 11:29 am

that should just work, make a reproducible example and attach that to a issue in our jira
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8829
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Methods

Who is online

Users browsing this forum: No registered users and 15 guests

cron