Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Auto Tabbing

Avatar

Former Community Member

I have a function that automatically tabs to the next field once it has reached the last cell of a comb field, see code below.  My problem is I want to be able to do the same thing with a standard text box both when the length is limited to a set number of characters and also when the length is limited to the visible area.  I bolded the position where I was able to get the number of cells for comparison to the current number of characters.

Any ideas on getting the length limit?  Harder, I assume, finding out if it has reached the limit of the visible area?  A resource of how you figured it out is always appreciated since all the docs I read have not helped on this one.

Thanks

CaseNumber::change - (JavaScript, client)

func.autoTab(this, xfa.event);

function autoTab(currentField , fieldEvent)

{

    try

    {

       if (fieldEvent.newText.length == currentField.resolveNode("ui.#textEdit.comb").numberOfCells)

        {

            var sNextField = currentField.traversal.resolveNode("#traverse").ref;

            if (sNextField != null)

            {

             xfa.host.setFocus(sNextField);

            }

        }

    }

    catch(ex)

    {

        console.println(ex);

    }

}

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Calling the function (or just scripting setFocus) from the full event should cover the comb field and the field set to "limit to visible area". It will probably also work for fields, which are set to a maximum number of characters. I think this will make your script much simplier, as you should not have to test each condition.

Instead of a function maybe look at propagating the setFocus() script from the full event of the root node. See here: http://blogs.adobe.com/formfeed/2011/06/propagating-events.html.

Lastly, I am not sure about the user experience. If they have their head down looking at the keyboard, will they appreciate that as they type the focus is changing to different fields?

Hope that helps,

Niall

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi,

Calling the function (or just scripting setFocus) from the full event should cover the comb field and the field set to "limit to visible area". It will probably also work for fields, which are set to a maximum number of characters. I think this will make your script much simplier, as you should not have to test each condition.

Instead of a function maybe look at propagating the setFocus() script from the full event of the root node. See here: http://blogs.adobe.com/formfeed/2011/06/propagating-events.html.

Lastly, I am not sure about the user experience. If they have their head down looking at the keyboard, will they appreciate that as they type the focus is changing to different fields?

Hope that helps,

Niall

Avatar

Former Community Member

It's all about where you put things. Yes doing this

xfa.host.setFocus(this.traversal.resolveNode("#traverse").ref);

In the "full" event works perfectly for both limit by length and limit to visible area.

As for the user experience I agree with you, but the customer is always right

Thank you so much

Avatar

Former Community Member

actually just found a possible issue, this goes back to the user wanting something that might not be for the best.  When I do this

xfa.host.setFocus(this.traversal.resolveNode("#traverse").ref);

If I have alread filled out a field, say social security number, and then I go to the field before it in the tab order, say last name, if I get to the end of last name focus is set to SSN, the entire contents of SSN is highlighted and then completely over written by the next character I type.  One solution I suppose is to check to make sure the next field is empty before changing focus, easy enough, but I can already foresee them wanting the cursor just set to the first index of the field so

xfa.host.setFocus(this.traversal.resolveNode("#traverse").ref.<location index 0>);

If one character of a string is over written, no big deal change it back, but better than overwriting everything. I am going to look into this but they want it COB today so might have to go with checking that the next field is blank before reseting focus.