I use the following code to loop through all form elements to set read only etc…etc it has worked really well until now. I have found that the JsplitPane bean does not have a .getName() function, so my code breaks at this point in the loop, I was hoping that someone may be able to suggest a way of bypassing that element all together.
var check;
for ( var i = 0 ; i < elements.length ; i++ )
{ //loop through all elements and filter by 'V'
if(elements[i].getName()){
check = elements[i].getName();
check = check.slice(3,4);
}
if(check == 'V'){ //check to see if there is a 'V' in the element name @ pos 4
var vColumn = elements[i].getDataProviderID()//get column data provider
if(!forms[vFormName][vColumn]){ //check if empty
elements[i].bgcolor = '#ffbbbb'//if empty set bg to red
vError = 'false' //tell dialog to open
} else {
elements[i].bgcolor = '' //if feilds are correct set bg to default
}
}
}
if(vError == 'false'){ //show dialog if 'vError' is false
plugins.dialogs.showDialog('Alert','Please fill in Highlighted Fields !')
} else { //if all records are validate true
for ( var i = 0 ; i < elements.length ; i++ )
{ //loop through all button elements and set to enabled = false
check = elements[i].getName();
check = check.slice(0,3);
if (check == 'btn'){
elements[i].enabled = false
}
}
Another option is to modify your existing code to check for the presence of a getName property before running it.
if(elements[i].getName && elements[i].getName()) {
//continue with code
The added benefit here is that it should work with any element that Servoy hasn’t wrapped up, not only the splitpane, but any of the other stock beans.
wvitpr:
Troy, could you explain the difference between the following please ?
Sure.
elements_.getName gives the value of property getName. In the case of any normal element (not the ones you get by placing a bean on a form), getName is a function. So when you put the () on the end of it, like elements*.getName(), you are executing a function. If that function doesn’t exist, it will complain._ Since we’re doing an && comparison, Servoy will stop evaluating the terms as soon as it encounters one that is false. Consider the following code snippet for three different types of form elements.
_*_ <em><em>if (elements_.getName && elements*.getName()) {*_</em></em> <em><em>_*_ _1- On a JSplitPane, elements.getName is undefined, so the conditional is false and nothing more is run. 2- On an unnamed field, elements.getName is non-null, so it continues on to elements.getName(), which is null (the field doesn’t have a name). So it stops there.* 3- For a named label, both return non-null values, the condition is met, and your code continues._