How can I access the styleName of a form?

Looking at the style samples of Servoy I see that there are as many forms as styles defined.
I tried several these options:
forms.Autumn.styleName
forms[“Autumn”].styleName

forms.Autumn.elements.styleName
forms[“Autumn”].elements.styleName

forms.Autumn.controller.styleName
forms[“Autumn”].controller.styleName

but it looks like I cannot get access to the styleName property of a form. :?

No doubt I am overlooking something here, after all, it is a form property so it should be possible to acces that.
Who can shed some light on this?

Hi Boudewijn,

Not every form property is a run-time property as you already found out. Once a form is loaded the styles are set.
You can only access the style property when you use the solutionModel which effectively means you alter the blueprint (in memory) of the form and then recreate it. And recreating a form is a substantially different action (internally) then just setting a form property if you know what I mean.

What are you trying to do ?

While studying on the styleclasses sample I saw that using the dropdown combo does not change the style of a form but it simply loads another form.
That makes this dropdown combo just another form of a menu and not a part of a form that changes the form itself.

So, I was trying to access the stylename property and see if changing that in runtime would alter the form lay-out.
Seems like this is not possible so much to wish for…

Maybe I should ask for a refresh() method of forms and controls…
change the stylename and refresh() the form (like thisform.refresh() ). Where the form’s refresh automatically should refresh all the controls on it as well.

Hi Boudewijn,

Please read Robert post: all you ask for is already possible: it’s called the solutionModel.

Paul

and your refresh() method is controller.recreateUI() (when using the solution model first to alter stuff)

Well,

I tend to design my forms visually, that way I see what I am doing.
I guess this is something I have to forget about then. Hmm, OK, back to the days I started developing software, all code, nothing visual.
Ah well, why not, “for aul’ lang syne”! :roll: begorrah…

I tend to design my forms visually, that way I see what I am doing

And so you do in Servoy as well. You asked how to programmatically alter stuff. We showed you the way…

Paul

I asked how to programmatically change properties in a visually designed form.
The answer is clear, you cannot (at least not for all properties.)

Boudewijn:
I asked how to programmatically change properties in a visually designed form.
The answer is clear, you cannot (at least not for all properties.)

Yes you can, you can do it this way (which is pretty easy):

var form = solutionModel.getForm('myform');
form.styleName = "newStyle";
forms.myform.controller.recreateUI();

So altering a form which you created visually is also possible with the solutionModel.

First results don’t look good.
Will test further this afternoon on my way home.
Some message about stale forms :(

then you did not call recreateUI()

jcompagner:
then you did not call recreateUI()

I got an error before I reach that point.
later tonight I will post one or more videos explaining what I expect.

Servoy makes it a big deal to make the VFP community part of their community.
So far, it is all VERY disappointing, more so. I was asked to leave a project I participated in because of the limitations Servoy puts on us. :evil: :twisted: :evil: :twisted:

I made it a big deal to tell the VFP community what Servoy COULD bring. I now tend to tell them to stay away from it as far as they can.

Hi Boudewijn,

Not sure what limitations you are talking about but why don’t you show us the code that errors for you.
Rick gave you 3 lines of code that does exactly what you asked for in this thread.

For all clarity, I am testing the servoy_sample_style sample.

the error I got is:

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:‘Autumn’ with instances: [Autumn]
at C:\servoy_workspace\servoy_sample_styles\globals.js:92

the code:

	var cShowform = globals.curStyle
	cShowform = utils.stringReplace(cShowform,'\r','')
	var cformToShow = solutionModel.getForm('HunterGreen')
	cformToShow.styleName = 'svy_'+cShowform;
	forms[cformToShow].controller.recreateUI();

I can assure I did NOT use the HunterGreen form before.
I got this error as well. I’m getting bollocks… :? :twisted: :?

TypeError: Cannot read property “controller” from undefined (C:\servoy_workspace\servoy_sample_styles\globals.js#93)
TypeError: Cannot read property “controller” from undefined (C:\servoy_workspace\servoy_sample_styles\globals.js#93)
at C:\servoy_workspace\servoy_sample_styles\globals.js:93 (goForm)

Boudewijn,

So I understand that the ‘form’ “HunterGreen” does not exist? Then DONT use .getForm()!
Because you want to get the formInstance which does NOT exist in the blueprint of your solution.

var form = solutionModel.getForm('myform'); // ENSURE THAT myform DOES EXIST IN MY SOLUTION
form.styleName = "newStyle";
forms.myform.controller.recreateUI();

The solution of your problem is rather easy:

var form = solutionModel.newForm('HunterGreen'); // THIS MAKES A NEW FORM IN MEMORY;
form.styleName = "newStyle";
forms.HunterGreen.controller.show();

If this still does not work, please provide the code that you use. Because this should work instantly.

ROCLASI:
… why don’t you show us the code that errors for you.

var cShowform = globals.curStyle
cShowform = utils.stringReplace(cShowform,'\r','')
var cformToShow = solutionModel.getForm('HunterGreen')
cformToShow.styleName = 'svy_'+cShowform;
forms[cformToShow].controller.recreateUI();

ROCLASI:
Rick gave you 3 lines of code that does exactly what you asked for in this thread.

I use a visually designed form and I want to alter that in code, as above.
The sample I used is the servoy_sample_styles, the codesnippet is in the globals.goform

I am redoing my video now since I left out some important points in the original one.
Will post that on youtube.

One of the reasons his code errors is due to a clearcut programming error:

var cformToShow = solutionModel.getForm('HunterGreen')
   cformToShow.styleName = 'svy_'+cShowform;
   forms[cformToShow].controller.recreateUI();

solutionModel.getForm(‘HunterGreen’) returns a JSForm object, which he puts in variable “cformToShow” and then he does this: “forms[cformToShow].”. Big programming error.

Paul

Bonkie:
Boudewijn,

So I understand that the ‘form’ “HunterGreen” does not exist? Then DONT use .getForm()

See the attached picture. HunterGreen DOES exist.

This comes from the servoy_style_sample in which the form HunterGreen is included.
[attachment=0]HunterGreenDOESExist.png[/attachment]

Boudewijn:

Bonkie:
Boudewijn,

So I understand that the ‘form’ “HunterGreen” does not exist? Then DONT use .getForm()

See the attached picture. HunterGreen DOES exist.

This comes from the servoy_style_sample in which the form HunterGreen is included.

Ok my bad… But did you read Pauls post above?

pbakker:
One of the reasons his code errors is due to a clearcut programming error:

var cformToShow = solutionModel.getForm('HunterGreen')

cformToShow.styleName = ‘svy_’+cShowform;
forms[cformToShow].controller.recreateUI();




solutionModel.getForm('HunterGreen') returns a JSForm object, which he puts in variable "cformToShow" and then he does this: "forms[cformToShow].". Big programming error.

Paul

You could try this code (which should work…)

var cformToShow = solutionModel.getForm('HunterGreen')
   cformToShow.styleName = 'svy_'+cShowform;
   forms.HunterGreen.controller.recreateUI();

pbakker:
One of the reasons his code errors is due to a clearcut programming error:

var cformToShow = solutionModel.getForm('HunterGreen')

cformToShow.styleName = ‘svy_’+cShowform;
forms[cformToShow].controller.recreateUI();




solutionModel.getForm('HunterGreen') returns a JSForm object, which he puts in variable "cformToShow" and then he does this: "forms[cformToShow].". Big programming error.

Paul

So, where can I find clear documentation on the difference between the two ways of doing this. :?:
From my POV I see a collection of forms and I access one of the items in the collection using forms[cformToShow] which is AFAIK:

  • access the object forms and select in that object the cFormToShow item
    another way of doing the same (from my POV, since I cannot find any documentation on this) is forms.Huntergreen, which is in my idea (since I have nop docs telling me different
    Access the forms object and get the Huntergreen property (Which can be an object as well of course).

So, if this is a clearcut programming error then the lack of documentation on issues like this is a clearcut documentation error. Making the “clearcut programming error” less obvious than stated here. :?
Especially for people who are not so well versed in the tool this is fuzzy logic.
So the “big programming error” you talk about here is due to a “big documentation error”.

The reason I did the forms collection is because, as I see it, there is a collection of forms in the application.
It occurred to me that I could access that collection. Apparently not so.
for sure, Java is not an easy language to learn.