Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!

setting focus to new instance of a field...need help.

Avatar

Former Community Member

Hi there,

I have a flowed form which consists of multiple subforms. I have one subform which is basically one textfield that is set to a min of 1 and a max of 5.

These are to correspond to fields in our system of record that have 5 fields for company long name with a 36 character field limit.

I've got the limits set up just fine and I have added simple script to add a new instance when the user exits the field.

The focus goes to the next field set in the tab order but what I want is the focus set on the new instance of field created but I have not been able to find an example of how to do that.

Any suggestions would be greatly appreciated. Thanks!

5 Replies

Avatar

Former Community Member

I have tested it roughly, so you will have to help yourself a bit but I can try to give you a good hint.

I have a subform, Sub1, which has just one textfield, TextField1.

On TextField1 exit event, I placed the following Adobe JS code:

Sub1.occur.max = "2";

var oSubform = xfa.resolveNode("Sub1");

var oNewInstance = oSubform.instanceManager.addInstance(1); // I think you probably managed this first part better than here

xfa.form.recalculate(1); // I THINK THIS IS IMPORTANT

var testIndex = oNewInstance.TextField1.index;

xfa.host.messageBox("Text Field Index in new Subform: " + testIndex); // TextField1 will conserve index 0 because it is the only textfield in the new Sub1

var NEW_TEXTFIELD = xfa.resolveNode("Sub1[1].TextField1[0]"); // However, Sub1 gets index 1 because it is not alone any more

xfa.host.setFocus(NEW_TEXTFIELD); // This actually sets focus on the newly created instance of TextField1 (actually Sub1 instance)

Avatar

Former Community Member

Thanks for the help, but it is not really working for me. It keeps producing the same message and instance number "0".

I'm trying to figure out why that is now but being very new at this, the answer will probably come slow! If I cant figure this out, I'll be back for more lessons!

Avatar

Former Community Member

Well,

I've been reading and trying various things but cant get anything to work like I want it to.

The sample provided works for 2 iterations but mine has to do this for up to 5 instances. I have not been able to figure out how to get this to work.

Anyone have any additional suggestions?

btw...here is my modified version. ES2 is whay I'm using.

Long_Title.occur.max = "5";

var oSubform = xfa.resolveNode("Long_Title");

var oNewInstance = oSubform.instanceManager.addInstance(1); // I think you probably managed this first part better than here

xfa.form.recalculate(1); // I THINK THIS IS IMPORTANT

var count = (this.Long_Title.nodes.length)

var testIndex = oNewInstance.Account_Long_Title.index;

xfa.host.messageBox("Text Field Index in new Subform: " + count); // TextField1 will conserve index 0 because it is the only textfield in the new Sub1

var NEW_TEXTFIELD = xfa.resolveNode("Long_Title[1].Account_Long_Title[0]"); // However, Sub1 gets index 1 because it is not alone any more

xfa.host.setFocus(NEW_TEXTFIELD); // This actually sets focus on the newly created instance of TextField1 (actually Sub1 instance)

Avatar

Former Community Member

Hi, my system is under maintenance and can't work with LiveCycle any more, so I'D WOULD ASK OTHERS TO HELP YOU (183 people reading this post).

However, in your first post you said you managed to add 5 instances of that subform containing only one text field. You should keep your original code and just use the part of my sample that helps you set focus on the last added text field.

If you wish to work with all my sample code, I can only give you this hint: Long_Title.occur.max is a read/write property. Don't take it up to 5 any time you run the script but increment it progressively by "Long_Title.occur.max++" or "Long_Title.occur.max = Long_Title.occur.max+1".

Avatar

Former Community Member

Thanks again for the tip. I will try melding my original and your suggestions on setting the focus portion.

If anyone else has done something similar I'd appreciate any other solutions.

Thanks!