Expand my Community achievements bar.

SOLVED

Autocomplete / Open drop-down list in STATIC forms

Avatar

Level 1

Hi everyone, so a while back I remembered looking for the ability to open drop-down lists on enter / click and have auto complete in a STATIC form. This behavior was thought to be impossible by design and many have searched for the function to no avail. I was upset enough at this and came up with an actual solution.

 

Sometimes there is a need to create a static form - I have one which is filled out by me (all fields accessible), then emailed to customer (only some fields accessible), then they fill out only the fields I allowed them to, then it gets emailed back to me completed. The reason it had to be STATIC XFA PDF is to make it locked and protected while still allowing others to use it. But I didn't like not being able to click in to a drop-down and losing the open and autocomplete feature... It is adjustable for fields with shorter input lengths, but the less than numbers ( < X) needs to change to reflect it. This is the best you can get anyways for fields that have over a 4 character input. You are welcome if this helps you!

 

Here is the code:

 

form1.Page1.DROPDOWNLIST::click - (JavaScript, both)
xfa.host.setFocus(this); // This is the code. You need all the lines to make it open the list and not instantly close it.

 

xfa.host.setFocus(this.Node);

 

xfa.host.openList("$")

 

form1.Page1.DROPDOWNLIST::change - (JavaScript, client)
if (xfa.event.newText.length == 1) { // This is what gives it autocomplete functionality.
xfa.host.openList("$");
}
if (xfa.event.newText.length == 0) {
xfa.host.openList("$");
}
if (xfa.event.newText.length < 2) {
xfa.host.openList("$");
}
if (xfa.event.newText.length < 4) {
xfa.host.openList("$");
}

1 Accepted Solution

Avatar

Correct answer by
Level 10

Sorry, what's the goal of this solution? 

This line of code makes no sense, since there's no scripting property or object called "Node" in LiveCycle.

 

xfa.host.setFocus(this.Node); // What's "Node"?


To get and keep a dropdown list open you only need a single line of code in the enter and change event of the dropdown list. 

 

xfa.host.openList(this);

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Sorry, what's the goal of this solution? 

This line of code makes no sense, since there's no scripting property or object called "Node" in LiveCycle.

 

xfa.host.setFocus(this.Node); // What's "Node"?


To get and keep a dropdown list open you only need a single line of code in the enter and change event of the dropdown list. 

 

xfa.host.openList(this);

Avatar

Level 1

Please understand this is for a STATIC form. If you create a dropdown list and put in the xfa.host.openList("$"); line in change or click it will just open and close quickly.

 

The solution I made for whatever reasons works... try it out to see.

Static Dropdown List 

 

Radzmar, the "This.Node" you are questioning gives the ability to select all text on re-enter (undocumented feature I discovered) 

 

To follow up with this: So with using (this.Node) it is done by choice as to make it cleaner looking... You can use (this.FluffyKittens) and it will accomplish the same thing. If you used (this.123) or (this.pdf) it won't.

You need a "jibberish" word after the . (no spaces and not too long). It is merely tricking the PDF in to highlighting the text on entry (mouse click) much like tabbing in to the field. You can call my "undocumented  feature" a bug or whatever if it helps you sleep at night, but it just works without having to use too much code. Again, my example works and I hope it helps someone.

 

- Adam

Avatar

Level 10

"Radzmar, the "This.Node" you are questioning gives the ability to select all text on re-enter (undocumented feature I discovered) "

 

To be honest, "This.Node" it's nothing else than nonsense. This code returns just "undefined". In result xfa.host.openList(this.Node) returns null, because "undefined" can't be resolved. The same story for xfa.host.openList("$"). It can't work. 

 

What you need is just xfa.host.openList(this); in the enter and change event ot the drop down list. It doesn't matter if it's a static or dynamic XFA form, it works the same way in both. 

 

And for the change event you can minimize the code to this:

var aFields = [PPN1, PCP1, PBA1, PCPS1, PPZC1],
aData = [
["", [null, null, null, null, null]],
["Dizz Bizznis Ltd.", ["5555551212", "Deezy Dealz (999) 555-1213", "420 Deeplaya Street", "Indahood, CA", "90420"]],
["Co Core Inc.", ["5558008135", "Jenny Tulls", "uite 69 - 17550 Durtea Way", "Las Vegas, NV", "69690"]]
],
cSel = xfa.event.newText;

aData.forEach (function (dataArray) {
// If selected text matches the first item on the nested array …
if (dataArray[0] == cSel) {
// … copy all related data into the fields.
aFields.forEach(function (oField, oIndex) {oField.rawValue = dataArray[1][oIndex];});
}
});
xfa.host.openList(this);

 

Avatar

Level 10

Well, sorry, but the code "This.Node" isn't a hidden feature but nonsense. It returns just "undefined" and that why xfa.host.openList(this.Node) returns just null, because "undefined" can't be resolved. The same story for xfa.host.openList("$"). That won't doesn't work at all. 

 

All you need is xfa.host.openList(this); in die enter and change event, as I already wrote. 

You also can optimize the code in the change event into: 

 

 

var aFields = [PPN1, PCP1, PBA1, PCPS1, PPZC1],
aData = [
["", [null, null, null, null, null]],
["User A", ["Phone 1", "John Doe", "Address 1", "City 1", "Zip 1"]],
["User B", ["Phone 2", "Jane Doe", "Address 2", "City 2", "Zip 2"]]
],
cSel = xfa.event.newText;

aData.forEach (function (dataArray) {
// If selected text matches the first item on the nested array …
if (dataArray[0] == cSel) {
// … copy all related data into the fields.
aFields.forEach(function (oField, oIndex) {oField.rawValue = dataArray[1][oIndex];});
}
});
xfa.host.openList(this);