Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

setFocus wont work after setting presence="invisible"

Avatar

Level 2

Hi,

i got a form with a button in it, that should jump to a combobox on another page which is hidden by setting this.presence="invisible" in its initialize event. The code in the click event of the button is the following:

comboBox1.presence="visible";
xfa.host.setFocus("comboBox1");

it does setting the presence to visible, but the setFocus seems to be ignored. When i click the button the second time, it will jump to the specified item.

Same phenomenon the other way round. When a value in the comboBox is chosen, i want the value to be copied to a textfield, set the presence of the combobox to invisible again, and return to the button with another setFocus instruction. To reach this, i did the following in the exit event of the ComboBox:

if(this.rawValue){
    textField1.rawValue = this.rawValue;
    this.presence="invisible";
    xfa.host.setFocus("button1");
}

the value and the presence got set, but (again) the setFocus instruction seems to be ignored.

it all works fine, if i outcomment the presence assignments. Could somebody tell me the reason why it wont work this way?

9 Replies

Avatar

Level 2

btw: it stays the same problem if i replace invisible with hidden.

Avatar

Former Community Member

You may need to specify the full path to the object that you are trying to set the focus on. In the script editor, if yo put your cursor in the place where the object name is to appear in the setFocus command, then hold the Alt key down and move the mouse to the field you want to reference. Once you hover over that field the cursor will change to a V. Once that happens click the mouse and the appropriate reference will appear in your command.

Paul

Avatar

Level 2

Thanks for your reply, but the V thing didnt work.

When i type in the complete path to the target item like:

xfa.host.setFocus("FormName.#subform[1].comboBox1");

it wont work either. I still have to click the button twice until i get the result i wanted.

In between i found a little workaround:

The target items are put on the top of an empty page, and only the current used one is visible. When the item is left(value is chosen) it returns to hidden state again. This is a kind of a solution, but not a satisfying one. Especially when returning to the buttons this solution is not really acceptable, because i still have to return to the top of the page they are belonging to, which is very annoying when u have a lot of items on a single page.

Avatar

Former Community Member

It worked in my sample that I tried ....can you post your form so I can see what is going on?

Paul

Avatar

Level 10

Could the quotes be confusing it? I don't think you need the quotes inside the brackets.

Avatar

Level 2

Sorry for being late on this. Still tryin to solve the issue. Attaching a sample file that illustrates the problem.

@Jono: if i dont use the quotes i get an error

Avatar

Level 10

Ok, you have some script problems going on. I've attached a new file with them fixed up.

When you are in the Script Editor and want to get the path to another object use the CTRL key and click on the object whose path you are trying to get. Your cursor needs to be in the Script Editor and you need to be able to see the object you are trying to click on. When you hold down the CTRL key and mouse over a valid object it will turn to a "V" - click on the object and the path will be inserted in your script.

So, where you had:

DropdownListe1.presence="visible";
xfa.host.setFocus("DropdownListe1");

It should be:

xfa.resolveNode("#subform[1].DropdownListe1").presence="visible";
xfa.host.setFocus(xfa.resolveNode("#subform[1].DropdownListe1"));

File attached - I moved the second subform to the first page so it was easier to see what was going on.

The code on the dropdown list looks a little odd, but I'm not sure exactly what you're trying to do - seems to work though.

Avatar

Level 2

Ok, i tested your PDF, first line in the click-event works well, seems like the resolve instruction is what i was looking for.

But the second line still throws an error to the debugger, and doesnt perform the jump (that is why i was putting the combo on the second page, to visualize the jump). Unfortunately i'm only able to show you the thrown error msg in german, dont have the english version of the designer:

Ausnahmefehler in Zeile 2 der Funktion oberste_Ebene, Skript XFA:Formular1[0]:#subform[0]:Button1[0]:click

GeneralError: Vorgang fehlgeschlagen.
XFAObject.setFocus:2:XFA:Formular1[0]:#subform[0]:Button1[0]:click
Unterschiedliche Argumente im Eigenschaft- oder Funktionsargument


to my this looks like the arguments of the setFocus instruction are wrong, but i can't image in which way.

Little offtopic: how can i embedd "code" in a post like this. Just see "insert image/video/link/table", "quote", "emoticons".

Avatar

Level 10

Not sure what's happening, it's not generating any errors for me.

You can format code in these forums by using the >> button on the button bar, right beside the smiley face. Choose Syntax Highlighting and then your preference. Plain seems to work the best for javascript.