You need to sign in to do that
Don't have an account?
BobB
Pressing Enter, Tabindex, Button Order, where is the cursor?
I would think this would be a simple thing but I can't find it. The closest is JavaScript and I would like to keep it very simple indeed.
I have a section of a page that is for input. Code below.There are a few things that don't work like I would expect:
- When the page comes up the cursor is on Contributor Last Name, tabindex=1 not Contributor First Name, tabindex=0 as I would expect.
- If I enter something in a field, any field, and then press enter what runs is the second button, Export Page, not the first, Run Search, as I would expect.
- I would like to explicitly place the cursor on a field or button regardless of tabindex. Is there a way to do that?
Are my expectations wrong? What am I missing here? Does all of this have to be done in JS?
Thanks... Bob
<table width="100%" border="0"> <tr> <td width="200" valign="top"> <apex:pageBlock title="Search Criteria" mode="edit" id="criteria"> <table cellpadding="2" cellspacing="2"> <tr> <td style="font-weight:bold;">Contributor First Name<br/> <apex:inputText id="contributorFname" tabindex="0" value="{!contributorFname}"/> </td></tr> <tr> <td style="font-weight:bold;">Contributor Last Name<br/> <apex:inputText id="contributorLname" tabindex="1" value="{!contributorLname}"/> </td></tr> <tr> <td style="font-weight:bold;">Contributor State<br/> <apex:inputText id="contributorState" tabindex="2" value="{!contributorState}"/> </td></tr> <tr> <td style="font-weight:bold;">MOC First Name<br/> <apex:inputText id="MOC_Fname" tabindex="3" value="{!MOC_Fname}"/> </td></tr> <tr> <td style="font-weight:bold;">MOC Last Name<br/> <apex:inputText id="MOC_Lname" tabindex="4" value="{!MOC_Lname}"/> </td></tr> <tr> <td style="font-weight: bold;">Record Limit<br/> <apex:selectlist tabindex="5" value="{!soqlLimitPage}" multiselect="false" size="1"> <apex:selectOption itemValue="limit 20" itemLabel="20 Records"/> <apex:selectOption itemValue="limit 40" itemLabel="40 Records"/> <apex:selectOption itemValue="limit 80" itemLabel="80 Records"/> </apex:selectlist> </td></tr> <tr> <td style="font-weight: bold;"><br/> <apex:commandButton action="{!runSearch}" tabindex="6" value="Run Search" rerender="results,debug" id="theSearch"/> </td> </tr> <tr> <td style="font-weight: bold;"><br/> <apex:commandButton action="{!$Site.CurrentSiteUrl}/apex/ContributionsToCSV_v1" tabindex="7" value="Export Page" id="theExportPage" /> </td> </tr> </table>
When the page comes up the cursor is on Contributor Last Name, tabindex=1 not Contributor First Name, tabindex=0 as I would expect.
Part 1 of the mystery solved: Tabindex=1 gets the focus, not 0. The JavaScript made no difference.
All Answers
1. If you refresh the page, the cursor stays at where it was previously located before reloading. Could this be the issue? I.e. when you come from a different page, does this problem still occur? Also, I think tabindex just arranges the order, but i'm not sure if it automatically focuses to the first tabindex.
2. I am not sure of this. I would also Run Search to execute. Try to interchange the two and see which one is executed.
3. You can use javascript here: document.getElementById("commandFname").focus();
Thanks, kerwintang. Pls see below....
1. If you refresh the page, the cursor stays at where it was previously located before reloading. Could this be the issue?
Refresh either by F5 or reentering the URL produces same results. Cursor at the second input box.
I.e. when you come from a different page, does this problem still occur?
Yes.
Also, I think tabindex just arranges the order, but i'm not sure if it automatically focuses to the first tabindex.
2. I am not sure of this. I would also Run Search to execute. Try to interchange the two and see which one is executed.
Clicking the buttons works fine. Exporting works fine. I tried swapping the order of the buttons and got the same results.
3. You can use javascript here: document.getElementById("commandFname").focus();
Thanks. I'll try this. Will solve part of the problem anyway.
...Bob
When the page comes up the cursor is on Contributor Last Name, tabindex=1 not Contributor First Name, tabindex=0 as I would expect.
Part 1 of the mystery solved: Tabindex=1 gets the focus, not 0. The JavaScript made no difference.
But wait... There's more... If I remove the export button altogether, enter something in the first box, then press enter nothing happens. No action at all.
So, I guess what I need to know is: No matter where I am on the page, if I press enter how can I ensure that the action is Run Search?
No doubt very simple but I don't know what it is.
Thanks.... Bob
Are you wrapping your table and fields inside a <form> tag? If so, can you view the source of the generated page.. and post the HTML generated by the Run Search button. :)
This is as it comes up the first time. After clicking Run Search follows:
After Run Search click with al in first text box:
Thanks for your help.... Bob