In reading through the Forum I gather that one can requestFocus in a
Portal (and field of course) since last April or so and I presume that one
can do that in a tabpanel too. However I am having a devil of a time
trying to get the syntax right and can’t seem to find any examples.
I have a method that is looping through the related records in the tab
panel doing a check on a particular field. That all works fine with:
for ( var i = 1; i <= ipox_master_to_ipox_stains.getSize(); i++ )
{
var record = ipox_master_to_ipox_stains.getRecord(i);
if ( record.score == ‘’ || record.score == null )
{ do stuff }
}
Everything in the loop works fine except that I can’t get the syntax right
for requesting focus to the field ‘score’ in that related record within my
tabpanel. It always comes up with object undefined. I’m sure I am
missing something obvious but can anyone help point me in the right
direction please? Thanks a lot.
How do you request focus? I don’t see the code so it is hard to say what you do wrong. The basic thing to ask is would be ‘is the element named’? Or do you access it by index?
Thanks for the help and I’m sorry I didn’t make it clearer. The element in this case is a field that lies within a related tab form on a form. The element itself (the requestFocus field) is named but naturally not on that form as it lies within a tab panel. So in the method I am in a ‘for’ loop going through the related records within the tabpanel when an ‘error’ is found. After a dialog box alerting the user to the error, I want to gain focus in the proper field for the user to correct the error. At that point I use:
ipox_master_to_ipox_stains.setSelectedIndex(i);
in which ipox_master_to_ipox_stains is the relation. That works fine and I can see that the correct record within the tab panel is selected. Then when I try to requestFocus on a field within that record is when I can’t get it correct. By going to the form on which the tab panel is based and selecting the named field ‘score’ and the property requestFocus I get:
I don’t get an error message but I also don’t get the focus. When I try other things like referring to the tab panel on the form that I am viewing and then the actual named element on the related form ‘signout_stains’ I get messages that the item I am referring to is undefined and has no properties.
I have tried such things as :
I’m all over the place with wild guessing!
So basically I don’t know how to access an ‘element’ and use its properties that is located within a tab panel on a particular form. I can access the record in question but not the elements within it. Is this any clearer? Thanks,
This one:```
forms.signout_stains.elements.score.requestFocus();
What I (still) don't know is what your code looks like...
Are you doing other things after you requested focus? If so, are you doing something that takes the focus away?
Thanks for your reply. That is what I thought was correct and I don’t get an error message when it runs. However I have been testing it by stepping through the method using the debugger so I don’t think it is anything else that follows that. As soon as I run that line of code there is no focus as far as I can tell. The line following that line of code in fact is just
return;
to simply leave the method.
There are various other checks in this same method. On each of them as soon as they find something wrong, I throw up a warning dialog box and then request focus to the field they need to correct. All of the other fields though are ‘native’ to that form, i.e. they do not reside within the tab panel. With the others it does work fine. I don’t have the actual code in front of me this moment but I’ll send it off later today.
Thanks again for your patience. I didn’t send it earlier because I thought it would just make it more confusing.
Problem solved!
There were two problems. One I was only ever running it from the debugger and two I was using ‘.getRecord’ instead of ‘setSelectedIndex’. It actually was working using .getRecord but when running it from the debugger in going back and forth between the editor and the form it would lose focus before I got there which didn’t happen on the other items outside of the tabpanel when I requested focus.
Your message saying that the code was right gave me the confidence to run it directly without debugging and then the focus showed up! At that point I realized that with .getRecord the focus was always only going to be in the first row in the tabpanel regardless of whether that was the row that had the problem. So then I changed it to setSelectedIndex and everything works great! There was just one other stumbling block for me at least and that was the syntax of the setSelectedIndex when using it with relations as in this case. The manual says under Methods, Form relations for setSelectedIndex, Syntax:
I’m sure I’m missing something here but in my case using a tabpanel holding the related records and including the first part (‘forms.formname’) would give an undefined error. If I leave the forms.formname off then it works great. If it helps anyone, below is the code that I am using in my method. The point of the method is to check to make sure the MDs here have completed a case completely before they ‘sign out’ on it. So if they forget something it gives them a warning message, reverses their signing out and gives them focus in the field that they omitted. The form that they are on when they are doing this is the parent record which also has child records in a tabpanel. The first part of this is related to the records in the tabpanel and that tabpanel is based on the form ‘signout_stains’.
for ( var i = 1; i <= ipox_master_to_ipox_stains.getSize(); i++ )//loop through the records in the tabpanel
{
ipox_master_to_ipox_stains.setSelectedIndex(i);//.getRecord also works fine for checking the if statement below but not for gaining focus later
if (ipox_master_to_ipox_stains.score == ‘’ || ipox_master_to_ipox_stains.score == null)
{
plugins.dialogs.showWarningDialog(‘No Score!’, ‘You cannot sign out when one or more Antibodies have no score’,‘OK’);
faculty_name = null;
forms.signout_stains.elements.score.requestFocus();
return;
}
}
if ( tissue_code == null || tissue_code ==‘’ )
{
plugins.dialogs.showWarningDialog(‘Attention!’, ‘You cannot sign out without entering a tissue code’,‘OK’);
faculty_name = null;
elements.tissue_code.requestFocus();
return;
}
if ( comment_txt == null || comment_txt ==‘’ )
{
plugins.dialogs.showWarningDialog(‘Attention!’, ‘You cannot sign out without entering a case comment’,‘OK’);
faculty_name = null;
elements.comment_txt.requestFocus();
return;
}
date_created = new Date();
if (name_creation == null)
{
name_creation = security.getUserName();
}
name_modification = security.getUserName();
globals.OmitThisRecord();