how do you determine an element type?

Questions, tips and tricks and techniques for scripting in Servoy

how do you determine an element type?

Postby eKelman » Wed Apr 27, 2011 11:57 pm

Hi all,

I was wondering if someone could tell me what property or call I could use to determine the displayType of an element.

I am looping through the elements on a form and need to determine whether or not it is a text area.

Thanks
Ernest
Kelman Technologies
eKelman
 
Posts: 52
Joined: Tue May 12, 2009 9:09 pm

Re: how do you determine an element type?

Postby jcompagner » Thu Apr 28, 2011 12:15 am

see: getElementType() on elements

for 6 you can do for example: if (element instanceof RuntimeTextField)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: how do you determine an element type?

Postby eKelman » Thu Apr 28, 2011 1:25 am

Johan,

Thank you.
Ernest
Kelman Technologies
eKelman
 
Posts: 52
Joined: Tue May 12, 2009 9:09 pm

Re: how do you determine an element type?

Postby antonio » Sat Apr 30, 2011 5:05 pm

Johan,

I made this global method that uses getElementType(), to change the background colour when entering any (named) field on a form via the onElementFocusGained and onElementFocusLost form events. I want only to do this for TEXT_FIELD and TYPE_AHEAD.

Code: Select all
function onElementFocusChanged(event) {
   var vElem = event.getElementName()
   var vEventType = event.getType()
   var vForm = event.getFormName()
   if (vElem && vForm)
   {   
      var vElementType = forms[vForm].elements[vElem].getElementType();
      application.output(vElementType)
      if (vElementType == ELEMENT_TYPES.TEXT_FIELD || vElementType == ELEMENT_TYPES.TYPE_AHEAD) // doesn't look nice on combobox
      {
         if (vEventType == "focusGained")
         {
            forms[vForm].elements[vElem].bgcolor =  '#ffffcc' // pale yellow
         }
         else { // reset to white on focus lost
            forms[vForm].elements[vElem].bgcolor = '#ffffff' // white
         }            
      }
   }
}

Works for TEXT_FIELD, but for TYPE_AHEAD fields I get this error
Java class "com.servoy.j2db.scripting.info.ELEMENT_TYPES" has no public instance field or method named "TYPE_AHEAD".

Checking the Application>Constants node, it's not there, nor COMBOBOX, even though both are returned with getElementType();

Can you suggest a work around?
Tony
Servoy 8 - 2022.03 LTS
antonio
 
Posts: 638
Joined: Sun Apr 02, 2006 2:14 am
Location: Australia

Re: how do you determine an element type?

Postby antonio » Sun May 01, 2011 12:24 am

Found that this throws an error

if (vElementType == ELEMENT_TYPES.TYPE_AHEAD)

But this works

if (vElementType == "TYPE_AHEAD")

Which I guess is obvious but I expected all the element types to be in the ELEMENT_TYPES set of constants.
Tony
Servoy 8 - 2022.03 LTS
antonio
 
Posts: 638
Joined: Sun Apr 02, 2006 2:14 am
Location: Australia

Re: how do you determine an element type?

Postby pbakker » Mon May 02, 2011 9:28 am

Hi Antonio,

The anomaly of the missing element type constants is something already fixed for the upcoming Servoy 6.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: how do you determine an element type?

Postby antonio » Mon May 02, 2011 11:44 am

Thanks Paul, roll on V6!
Tony
Servoy 8 - 2022.03 LTS
antonio
 
Posts: 638
Joined: Sun Apr 02, 2006 2:14 am
Location: Australia


Return to Methods

Who is online

Users browsing this forum: No registered users and 7 guests