Looping through all page objects

I know in JavaScript on forms you can loop through all the objects on a page, for example to check all text boxes have some kind of value entered in them before a form is submitted. is there a way to do that same thing in servoy. what im looking to do is to be able to go through loop the objects on my form when i start up and if displayType=“COMBOBOX” then i do something to the combo box. is there a way to script that in servoy?

thanks ahead of time,
galexander

If you use a very strict naming convenction naming convention you can organize a sort of loop of form elements, just name your elements something like:
elment_1, element_2, …, element_n

and then for example you can use a loop like this for setting element visibility:

for ( var i = 1 ; i < 1000 ; i++ )
{
   var element_name = 'element_'+i
   if ( element_name )
   {
     forms.form_name[element_name].visible = false
   }
   else
   {
     break
   }
}

I’m going on memory so check the code carefully.
Beware: it’s not really clever code though, naming your elements this way you loose indication of what they represent so you could find yourself in a hell of a time defining access security or calling a particular element by name.
Having said that I don’t remember a function to get the dispaly type of a field so I don’t think you will be able to change comboboxes or the like.

I think the code referred to was posted in Servoy Magazine by David Workman back in March.

for (var i in elements)
{
if (elements*.getName().slice(0,3) == ‘fld’)*
{
elements*.fgcolor = globals.fgcolor;*
elements*.bgcolor = globals.bgcolor;*
}
}
[/quote]
The article is a great resource - use this link http://www.servoymagazine.com/home/2005 … ek__2.html
Best regards
Graham Greensall
Worxinfo Ltd

for (var i in elements)
{
if (elements*.getName().slice(0,3) == ‘fld’)*
{
elements*.fgcolor = globals.fgcolor;*
elements*.bgcolor = globals.bgcolor;*
}
}
[/quote]
This is clever but this way you get all form elements not only fields.
If you name only your fields with my naming convention you can loop trough them only.

i think that code snippet from workman will work for me. wow thanks, i can manipulate that enough i think to get what i need going. I really apprechiate it the help from both of you.

thanks!

Hi Nicola,

ngervasi:

for (var i in elements)
{
if (elements*.getName().slice(0,3) == ‘fld’)*
{
elements*.fgcolor = globals.fgcolor;*
elements*.bgcolor = globals.bgcolor;*
}
}
[/quote]
This is clever but this way you get all form elements not only fields.
If you name only your fields with my naming convention you can loop trough them only.[/quote]
The ‘if’ condition within the loop deals with that sort of scenario as the formatting will only be applied to elements which begin ‘fld’
So there has been an implied naming convention here that all field element names will begin ‘fld…’
This then becomes fairly extensible in that your naming convention can handle many types of objects and then target only those specific object types for formatting
Cheers
Harry

Harry Catharell:
The ‘if’ condition within the loop deals with that sort of scenario as the formatting will only be applied to elements which begin ‘fld’

So there has been an implied naming convention here that all field element names will begin ‘fld…’

This then becomes fairly extensible in that your naming convention can handle many types of objects and then target only those specific object types for formatting

Cheers
Harry

Wooppss… I didn’t notice that.

Late hours lead to errors… errors lead to rage, rage leads to hate and hate leads to the darkside!

:-)

Have patience, young paduan and trust in the Force :-)

Harry Catharell:
Have patience, young paduan and trust in the Force :-)

I will, my Master. :-)