0
\$\begingroup\$

I am new to working with Unity3d, I need to navigate between several inputField, for this I have looked at the solution that is in: tab-between-input-fields, but always the FindSelectableOnUp() or FindSelectableOnDown() returns null, so my next is always null and always ends in: next = Selectable.allSelectables[0];

\$\endgroup\$
2
\$\begingroup\$

I did a small improvement to @virtouso answer. I start always with the first inputfield in my list and after the last inputfield I am reseting my counter to start again from beginning.

public  List<InputField> fields;
int _fieldIndexer;

private void Update()
{
    if (Input.GetKeyDown(KeyCode.Tab)) {
        if (fields.Count <= _fieldIndexer)
        {
            _fieldIndexer = 0;
        }
        fields[_fieldIndexer].Select();
        _fieldIndexer++;
    }
}


void Start () {
    fields = new List<InputField>{PreNameInput, FamilyInput, BirthdateInputField};
}
\$\endgroup\$
1
  • \$\begingroup\$ You can also change the List type to List<Selectable> to tab cycle through inputs and buttons, so users can tab to a button and hit enter to submit. \$\endgroup\$ – BatteryAcid May 11 at 3:39
1
\$\begingroup\$

A possible cause for the FindSelectableOnUp and FindSelectableOnDown returning null could be the value set under Navigation. Each Selectable (InputField is a Selectable) has in its inspector a section called Navigation.

enter image description here

This influences what FindSelectableOnDown and FindSelectableOnUp return. If vertical is not checked for any of the 2 InputFields you want to link for instance, they won't be able to navigate to each other. (Also note, the visualize button should show arrows in the scene view if Navigation is enabled for both elements)

For more info about how Navigation works, see this section in the manual

\$\endgroup\$
1
\$\begingroup\$

It seems you want to change focus between input fields by TAB button. I'm not sure there is a built-in function for this but you can simply write some code for this solution. For this, you have to make a list of your input fields. Then, on Press Tab Button, change the index and call the Select function. This is my example but you have to handle other things too:

public  List<InputField> fields;
int fieldIndexer;

private void Update() {
    if (Input.GetKeyDown(KeyCode.Tab)) {
        fieldIndexer++;
        fields[fieldIndexer].Select();
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.