Button in existing form

Questions, tips and tricks and techniques for scripting in Servoy

Button in existing form

Postby irenem » Fri Aug 27, 2010 1:34 pm

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:
Code: Select all
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?
Irene Meyer

Version: 6.0.5
Java version 1.6.0_29
Mac OS X Version 10.7.3
User avatar
irenem
 
Posts: 279
Joined: Tue Aug 28, 2007 2:09 pm
Location: Netherlands

Re: Button in existing form

Postby ROCLASI » Fri Aug 27, 2010 2:10 pm

Hi Irene,

You need to call controller.recreateUI() to let it show the changes you made.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Button in existing form

Postby irenem » Fri Aug 27, 2010 2:26 pm

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

Version: 6.0.5
Java version 1.6.0_29
Mac OS X Version 10.7.3
User avatar
irenem
 
Posts: 279
Joined: Tue Aug 28, 2007 2:09 pm
Location: Netherlands

Re: Button in existing form

Postby jcompagner » Fri Aug 27, 2010 3:58 pm

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)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Button in existing form

Postby mboegem » Fri Aug 27, 2010 4:09 pm

I'm surprised you don't have more errors:
Code: Select all
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
Code: Select all
if(solutionModel.getMedia('getMail.png' == null))

Guess this should be
Code: Select all
if(solutionModel.getMedia('getMail.png') == null)


Hope this helps
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1750
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam


Return to Methods

Who is online

Users browsing this forum: No registered users and 9 guests