Solution Model Getting Stale form(s) detected

Hi,

I am trying to add a onAction() method to a label created via the solution model. When I try to set the style (of a JSLabel) I get the error
“Stale form(s) detected, form(s) were altered by the solution model without destroying them first
The form(s) that are stale (can also be a parent form if form inheritance is used) are:”

Here is my code.

jsLabel = jsform.newLabel(row[0], (2 + ((index-1) * 122)), 10, 120, 20);
		jsLabel.styleClass 	= 'tab_inactive';
	    jsLabel.showClick   = false;
	    
		
		if ( sLastForm != row[1] ) {
	        // Get the new method definition
	        jsFunction = jsform.newMethod('function  onActionTab' +index+'() { 
	                                        forms.frm_navigation_bar.jsLabel.styleClass = "tab_active";   }');
	        // remember which form we last processed
	        sLastForm = row[1];
	    }

The moment this function runs I get the above error. Any ideas?

Regards,
Hareendra

It means that the form has already been loaded by servoy. If you want to change the blueprint of this form with the solutionModel then you have to remove it from the history:

history.removeForm(formName)

Hi,

I tried the following,

 jsFunction = jsform.newMethod('function  onActionTab' +index+'() { \
	                                        forms.frm_main.addNewTab("' + row[1] + '"); \
	                                        history.removeForm("'+sform+'");\
	                                        forms.frm_navigation_bar.jsLabel.styleClass = "tab_active";   }');

But i’m still getting the same error!

Regards,
Hareendra

My guess is that the error is related to the first line of the code you originally posted, so this line should be at the top of this code:

history.removeForm(sform);
jsLabel = jsform.newLabel(row[0], (2 + ((index-1) * 122)), 10, 120, 20);

Maybe it is a good idea for you to have a good look at the documentation of the Solution Model
https://wiki.servoy.com/display/DOCS/Solution+Model
or these video’s

Hi,

This error comes up when you try to modify the blueprint of the form and try to load the form when it is already loaded.

If we need to show the modified blue print, then we need to call the recreateUI of the controller as last line after modifying the content.

forms[jsForm.getName()].controller.recreateUI();

Even you can also remove the history before modifying and loading the form again as Jos suggested.

But, what this line trying to do ?

forms.frm_navigation_bar.jsLabel.styleClass = “tab_active”;

Here jsLabel is the actual form component or the label created via solution Model?

Hi,
yes, jsLabel is the label created via the solution model.

you cannot use it like that. You have to use the element name:

forms.frm_navigation_bar.elements['myLabel'].styleClass = "tab_active";

where myLabel is the name of the jsLabel you created with the solution model.

But reading your original post a little better, why are you creating a method for each label you create?
Why not create a single function in your frm_navigation_bar that handles the activation of the correct label?
something like this:

/**
 * form variable to hold the current active label
 *@type{String}
 */
var active_lbl = '';

/**
 * function to toggle the active tab
 * @param {JSEvent} event
 */
function onToggleTab(event){
  // first deactivate the current active tab
  elements[active_lbl].styleClass = 'tab_inactive';
  active_lbl = event.getElementName();
  elements[active_lbl].styleClass = 'tab_active';
}

and your function would look something like this:

  var jsMethod = jsForm.getMethod('onToggleTab');
  var jsLabel = jsform.newLabel(row[0], (2 + ((index-1) * 122)), 10, 120, 20, jsMethod);
      jsLabel.styleClass    = 'tab_inactive';
       jsLabel.showClick   = false;

Hi,
One problem is that elements do not have a styleClass property.
Regards,
Hareendra

Hi Hareendra,

styleClass is not a runtime property. You can set it using the solutionModel.

ROCLASI:
styleClass is not a runtime property. You can set it using the solutionModel.

ah yes I forgot about that.

You can also create 2 labels on top of each other and hide/show the correct label.