# Button in existing form

**URL:** <https://forum.servoy.com/t/button-in-existing-form/12749>\
**Category:** Classic Servoy\
**Created:** [August 27, 2010, 11:34am UTC](https://forum.servoy.com/t/button-in-existing-form/12749 "2010-08-27T11:34:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![irenem](https://avatars.discourse-cdn.com/v4/letter/i/977dab/32.png) [@irenem](https://forum.servoy.com/u/irenem)\
**Post date:** [August 27, 2010, 11:34am UTC](https://forum.servoy.com/t/button-in-existing-form/12749/1 "2010-08-27T11:34:56Z")

</div>

I try to ad a button in an existing form, but no mater what i get an 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:  
> Form name:‘nav\_cont\_main’ with instances: [nav\_cont\_main]  
> at /Users/meyer/servoy\_workspace5.1/coperta/forms/action\_list\_comp.js:551

this is the code:

```auto
var mediaURL = forms.login_settings_dev.logset_media_path
	var name = currentcontroller.getName()
	var form = solutionModel.getForm(name)
	history.removeForm(form)
	solutionModel.removeForm(form)
	if(solutionModel.getMedia('getMail.png' == null))
	{
	var ballBytes = plugins.file.readFile(mediaURL + '/testUp.png');
	var ballImage = solutionModel.newMedia('getMail.png', ballBytes);
	}
	form.removeButton('butNavCont')
	var methNavCont = form.getFormMethod('getFile')
	var butNavCont = form.newButton(null, 20, 6, 30, 30, methNavCont);
	butNavCont.imageMedia = ballImage
//Sorts the foundset based on the given string
forms.action_list_comp.controller.sort('act_date desc');

```

what am I doing wrong?

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [August 27, 2010, 12:10pm UTC](https://forum.servoy.com/t/button-in-existing-form/12749/2 "2010-08-27T12:10:55Z")

</div>

Hi Irene,

You need to call controller.recreateUI() to let it show the changes you made.

---

<div class="post-metadata">

**Author:** ![irenem](https://avatars.discourse-cdn.com/v4/letter/i/977dab/32.png) [@irenem](https://forum.servoy.com/u/irenem)\
**Post date:** [August 27, 2010, 12:26pm UTC](https://forum.servoy.com/t/button-in-existing-form/12749/3 "2010-08-27T12:26:58Z")

</div>

Hi Robert,  
it works, the error is gone, but the button isn’t created. And the console doesn’t return anything.  
Any idea why?

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [August 27, 2010, 1:58pm UTC](https://forum.servoy.com/t/button-in-existing-form/12749/4 "2010-08-27T13:58:32Z")

</div>

i dont know but there are a lot of stuff that will not work:

var name = currentcontroller.getName()  
var form = solutionModel.getForm(name)  
history.removeForm(form)  
solutionModel.removeForm(form)

that will never work  
a currentcontroller is the one that is shown. removeForm will return false and wont do anything.  
so i dont know what you expect that happens?

What you can try is also give the button a text so not null but “” (but i dont think that matters)

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [August 27, 2010, 2:09pm UTC](https://forum.servoy.com/t/button-in-existing-form/12749/5 "2010-08-27T14:09:40Z")

</div>

I’m surprised you don’t have more errors:

```auto
var name = currentcontroller.getName()
   var form = solutionModel.getForm(name)
   history.removeForm(form)
   solutionModel.removeForm(form)

```

As you use currentcontroller, I assume that the form is currently being displayed when you do this.  
This is the 1st reason you had the staleForm error.

Besides that, the ‘form’ arguments in history.removeForm as well as solutionModel.removeForm do expect a formname, while you pass a form object. These function can’t have worked.  
This is the 2nd reason that you had the staleForm error. (in case the form you are trying to alter isn’t displayed)  
If your form was being displayed these lines have no effect at all.

Then ```  
if(solutionModel.getMedia(‘getMail.png’ == null))

````auto
Guess this should be ```
if(solutionModel.getMedia('getMail.png') == null)

````

Hope this helps
