Delete a Form

I am creating a Form via the solutionModel like this:

_jsForm = solutionModel.newForm(_jsFrm_registerName,_jsFrm_databaseSelected,_jsFrm_,tableSelected,_jsFrm_styleName,_jsFrm_show_in_menu,_jsFrm_width,_jsFrm_height);

where the variable _jsFrm_registerName is some value. For this example it is set to ‘defaultRegister’. The problem I’m having is that later when a user performs a certain set of actions I need to completely delete/destroy/remove, etc. the form so the same code above can once again be ran. I’m using the following code to attempt to do this but I still get an error:

if(forms[_jsFrm_registerName]){
	var success = history.removeForm(_jsFrm_registerName);
	if(success){
		solutionModel.removeForm(_jsFrm_registerName);
	}
}

I get the following error though the first time the user tries to perform the delete action:

The name 'defaultRegister' already exists as another form

Does anyone see what I might be doing wrong?

Thanks,

Keith

Ok, so I figured it out and thought I’d share the answer in case others find themselves with the same problem. The form cannot be visible when trying to delete it so, in my case since I’m creating the form inside a Tabless Panel I simply did a removeAllTabs on the panel and then used the same code as I posted earlier and it all works fine. So, inside my method, the code now looks like this:

elements.tpForm.removeAllTabs();

if(forms[_jsFrm_registerName]){
   var success = history.removeForm(_jsFrm_registerName);
   if(success){
      solutionModel.removeForm(_jsFrm_registerName);
   }
}

_jsForm = solutionModel.newForm(_jsFrm_registerName,_jsFrm_databaseSelected,_jsFrm_,tableSelected,_jsFrm_styleName,_jsFrm_show_in_menu,_jsFrm_width,_jsFrm_height);

That is now working perfectly.

Keith