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:
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');
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)
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))
Guess this should be ```
if(solutionModel.getMedia('getMail.png') == null)