These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Setfocus - Navigation/Display

krm240
Registered: Apr 17 2009
Posts: 95

I am using a set of buttons in the MasterPage for navigation/Display
Click a button, and you unhide a specific section/page and go to it, click again and hides that section and at the moment, goes to a specific field at the beginning of the form.
eg: using xfa.host.setFocus("Main.Instructions.Header.Desc");

I would like to have the form remember the last field of focus prior to clicking the MasterPage Navigation button
Is this possible?

This way, when they click the button the second time, I can bring the user back to where they started prior to clicking the MasterPage Navigation button

Really do not want to set code in every field's exit event.

So the question is, is there a form variable that holds the last field of focus?

Celticbluestone
Registered: May 13 2011
Posts: 4
I'm looking to do something similar to what you describe. Did you manage to achieve this functionality and if so would it be possible to share the details with me? Thanks.
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi,

to make an undo function for the focus you will need to define some functions that will record and restore the SOM expressions of the focused fields.
Here's an example form.

You need a script object "Memory" with 3 functions.
One is to create, one to record and one to restore the focus history.

  1. // Set up the focusHistory
  2. function createHistory( field )
  3. {
  4. if (field.extras.nodes.namedItem("focusHistory") === null)
  5. {
  6. field.extras.nodes.append(xfa.form.createNode("extras", "focusHistory"));
  7. field.extras.focusHistory.nodes.append(xfa.form.createNode("integer", "current"));
  8. field.extras.focusHistory.current.value = 0;
  9. }
  10. }
  11.  
  12. // If the focus has chened, store it into the focusHistory
  13. function currentFocus( field )
  14. {
  15. var fHistory = field.extras.focusHistory;
  16. var fHistoryLenght = fHistory.nodes.length - 1;
  17. var fSOM = xfa.host.getFocus().somExpression;
  18.  
  19. if (fHistory.nodes.item(fHistoryLenght).value != fSOM)
  20. {
  21. var fHistory = field.extras.focusHistory;
  22. fHistory.current.value++;
  23. while (fHistory.nodes.length > fHistory.current.value)
  24. {
  25. fHistory.nodes.remove(fHistory.nodes.item(fHistory.nodes.length - 1));
  26. }
  27. var newItem = xfa.form.createNode("text", "focusSOM");
  28. newItem.value = fSOM;
  29. fHistory.nodes.append(newItem);
  30. }
  31. }
  32.  
  33. // Set focus to previously selected field
  34. function undo( field )
  35. {
  36. try
  37. {
  38. var fSOM = CurrentFocus.value;
  39. var fHistory = field.extras.focusHistory;
  40. if (fHistory.current.value > 0)
  41. {
  42. while (fSOM == fHistory.nodes.item(fHistory.current.value - 1).value)
  43. {
  44. fHistory.current.value--;
  45. }
  46. var fHistoryItem = fHistory.nodes.item(fHistory.current.value - 1).value;
  47. xfa.host.setFocus(fHistoryItem);
  48. fHistory.current.value--;
  49. }
  50. }
  51. catch(e)
  52. {
  53. xfa.host.setFocus(fHistory.nodes.item(1).value);
  54. }
  55. }
You also need a form variable "CurrentFocus" to temporary store the SOM expression of the currently focussed field.

The history gets stored in the extras object of a text field "HistorySOM", which also shows the currently focused fields.
Therefore it calls the function to create the focus history from it's initialize:Event.
  1. Memory.createHistory(this);

It can be hidden later, but actually it's visible for controlling.


The record the focus history the appropriate script is called from the enter:Event of every form field.
  1. CurrentFocus.value = xfa.host.getFocus().somExpression;
  2. Memory.currentFocus(HistorySOM);
  3. xfa.form.recalculate(1);
To undo the focus the function is executet from a buttons click:Event.
  1. Memory.undo(HistorySOM);

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs