You need to sign in to do that
Don't have an account?
Possible to determine current focus?
HI
I have a page that needs to do the occasional calculation then show the results afterwards which entails a section of the page to be rerendered. If the focus was within the rerendered area then the focus is lost. I want to put it back. I am aware that a lot of components that have an Action attribute also have a Focus attribute. Problem is I can't figure out how to tell it to return the focus to where it was. I am hoping that there is something like this:
focus="{!$CurrentPage.getComponentID.CurrentFocus}"
That would make life so easy. Not afraid of APEX or Javascript if they present a solution. Any and all help appreciated.
Regards
MellowRen
Apex will not help - it's not client side. Visualforce also does not have such a function.
My solution would be to store what element was in focus at the time the re-render was called.
for example:
This way you store what you were focusing on before the transaction, then set it afterward
Just make sure you don't rerender the area of the page with the script in it of courcse
All Answers
Apex will not help - it's not client side. Visualforce also does not have such a function.
My solution would be to store what element was in focus at the time the re-render was called.
for example:
This way you store what you were focusing on before the transaction, then set it afterward
Just make sure you don't rerender the area of the page with the script in it of courcse
JayNic
Thanks for your reply. Your solution partially worked for me. I have been playing but can't seem to get it to go. Here is a reduced version of my VF page:
As you can see, the big difference is that I (had to?) use an ActionSupport rather than ActionFunction. If I change the value in either huntPr or fredPr, and then click in the other, the focus is lost after the rerender.
If instead I click in sText (which is also rerendered) the focus survives! I have tried rerendering pricingBlock rather than the fields, I get the same problem.
Any ideas?
Regards
MellowRen
Since VF dynamically creates element ids and names on the fly, they might be changing for some reason after a re-render...
Try some alerts like so to see if the element is still there.
Also note that I changed your re-renders. You can just re-render the whole table since you're re-rendering all the dynamic bindings anyways.
If this doesn't work, then I would use 'document.getElementsByClassName' and give each of your input elements a unique class name eg:
and use document.getElementsByClassName('huntText')[0];
since you know that the style class will retain through the re-render. So rather than storing the active element, you just store the active elements class name, then re-query for it in the 'retainFocus' function.
JayNic
After a lot of playing around I finally got it to work. For the sake of completeness I'll put some notes here.
Why does 3 work like that? I have no idea, doesn't make sense to me. Can't complain though since it does what I want :-)
Thank you for your help (and js knowledge).
Regards
MellowRen