Tcomb-form-native: Tab / next to next field

Created on 20 Apr 2015  Â·  11Comments  Â·  Source: gcanti/tcomb-form-native

It would be great to be able to tab from one field to the next or display "Next" on keyboard.

Most helpful comment

It could be handled by tcomb-form-native, enabled or disabled by a prop in the Form component. This is something we would like to have, how do you feel about sending a PR? I'm glad to review.

All 11 comments

Yes, it would be nice.
Generally if it can be done by hand and a rule exists, it can be automated by tcomb-form(-native).
Currently how you do that with react-native? Could you provide a gist?

Was this issue closed because of no gist or because the feature was added?

Here is an example of how to do it: http://stackoverflow.com/questions/32748718/react-native-how-to-select-the-next-textinput-after-pressing-the-next-keyboar

In short, add an onSubmitEditing attribute to the TextInput:

<TextInput 
...
  onSubmitEditing={(event) => { 
    this.refs.foo.focus(); 
  }}
/>

Was this issue closed because...

Because of inactivity. BTW there's a solution for tcomb-form-native in the SO question you posted and that links to this issue https://github.com/gcanti/tcomb-form-native/issues/96 (no feature to add)

Excellent. Wasn't familiar with the getComponent api.

@gcanti the solution in SO is very specific to specific form.
I would expect tcomb-form-native to handle this dynamically.

This would be cool functionality to have; Is this something that tcomb-form-native should handle out of the box, or is that up to the user to control? 🤔

It could be handled by tcomb-form-native, enabled or disabled by a prop in the Form component. This is something we would like to have, how do you feel about sending a PR? I'm glad to review.

Any update on this?

+1, subscribing to thread

I agree it'd be nice to have this inside tcomb-form-native. Just wanted to leave a possible workaround for anyone coming to this issue (like I did). Add this method to the component with the form:

addNext = (nextFieldName) => {
        return {
            returnKeyType: 'next',
            onSubmitEditing: () => { 
                // Assuming your form ref is stored in this.form, change to your needs. 
                const target = this.form.getComponent(nextFieldName);
                if (target && target.refs && target.refs.input) target.refs.input.focus();
            }
        }
    }

and then in the config of your fields simply add

fields: {
    name: { label: 'Name', ...this.addNext('surname') },
    surname: { label: 'Surname', ...this.addNext('address') },

}

I know this is an old topic – but this is still an issue!

I can't use the solution above because onSubmitEditing is not fired when hitting the next button on Android. Tried with onBlur instead, which is fired, but then target.refs is just an empty object, so I cannot focus the next input. Any advice on how to solve this?

Here is the simplified code:

const formRef = useRef();

const Name = t.struct({
    firstname: t.String,
    lastname: t.String,
});

const options = {
    order: ['firstname', 'lastname'],
    fields: {
        firstname: {
            placeholder: 'First Name',
            returnKeyType: 'next',
            onSubmitEditing: () => console.log('submit editing'), // never fired
            onBlur: () => formRef.current.getComponent('lastname').refs.input.focus(), // input is undefined
        },
        lastname: {
            placeholder: 'Last Name',
            returnKeyType: 'done',
        },
    },
};

return (
    <KeyboardAvoidingView behavior='position'>
        <Animatable.View animation='fadeInUp' duration={400}>
            <Form ref={formRef} type={Name} options={options} value={formData} onChange={handleFormChange} />
        </Animatable.View>
    <KeyboardAvoidingView>
);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

pgmemk picture pgmemk  Â·  4Comments

pocesar picture pocesar  Â·  4Comments

alexicum picture alexicum  Â·  6Comments

muthuraman007 picture muthuraman007  Â·  4Comments

flyingace picture flyingace  Â·  5Comments