Form elements seem undefined

I have a form where I add another object/element in code in the form show as in:

var myForm = solutionModel.newForm("test",null,null,null,false,30,10)
//add a label
myForm.newLabel('Test', 20, 20, 120, 30)

In another function on that form I want access to that label.
So my first test was:

forms['testform'].elements['Test']

I get an ‘undefined’ back. :shock:

I DID add the object to the form, so why is it unaccessible from other functions?

Is there an hickup in the object model or am I doing something wrong here? :?

if both extracts are an exact copy of your code, it’s obvious:
you’ve created a form with the name ‘test’ but your trying to access the elements of form ‘testform’

hope this helps

you’ve created a form with the name ‘test’ but your trying to access the elements of form ‘testform’

And this code was running from the .js file of the testform.
from my POV I thus created an object IN testform, so that makes ‘test’ an object on the form ‘testform’.
meaning I created an object ‘test’ in ‘testform’, so I should be able to access that object from anywhere in the testform.
So I want to be able to access the ‘test’ object from whatever function or other object on the form ‘testform’.

I do come from an OOP environment and adding objects to a form there means I can access objects on a form from anywhere.

Also, a property or object on a form is not a variable
so I can code like:
// creating a variable.
local loObject as object
loObject = createObject(“form”)

a local variable is like a var in a function. only accessible in that function.

//creating an object
this.addproperty(‘oObject’, createObject(‘form’))
a property is accessible from anywhere (unless made hidden or protected).
or

thisform.newobject(“mytextbox”,“MyTextBoxClass”,“”,“param 1”, param nn")
In any method of the form I can now access this textbox as “this.mytextbox”
From any object on the form I can access this object as thisform.mytextbox
I sure hope I am not stepping on any toes here. it seems roclasi is quite P**ed off by the way I aks my questions.

Boudewijn Lutgerink

Boudewijn,

Please read Marc’s post carefully: you create a form with name “test” and then try to reference it by the name “testform”.

Paul

besides that you access the wrong form you also will not be able to access the label you created.
Because it is form.elements.elementname…

and JSForm.newLabel(text,xxxxx)

there text is the text of the label not the name…

so to be able to access it you have to do:

myForm.newLabel('Test', 20, 20, 120, 30).setName("test);

then if you created a form “test” then you can access the element through

forms['test'].elements['test']

Also when doing solutonModel.newForm() you are defining forms on a global level. it doesn’t matter where you call those
that newForm is a factory method going inside servoy, not a “normal” js object construction like:

var myobject = new Object()

The above would create a object in the current scope (in the function you are in or in the file if that is a global/form variable in the js file)

But that is not the same as solutionModel.newXXXX() those are servoy object generators on the global solution level.