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?
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:
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';
}