Search code examples
react-nativetcomb-form-nativetcomb

How to input button in tcomb react native


I want to put button in form for get current location and then put the value in coordinate

I tried this but it doesnt work

const validForm = t.struct({
    coordinate: t.maybe(t.String),
    buttoncoordinate: t.maybe(t.String),
});

let options = {
    i18n: {
        optional: '',
        required: ' *'
    },
    fields: {
        coordinate: {
            label: 'coordinate',
            stylesheet : textInput,
        },
        buttoncoordinate:{
            label:'',
            stylesheet : textInput,
            factory: props => (<Button{...props} onPress={() => console.log('pressed')} />
            ),
        },
    }
};


render() {
        return (
                    <View style={styles.formInput}>
                        <Form
                            ref="form"
                            type={validForm}
                            options={options}
                            value={this.state.value}
                            onChange={this._onChange}
                        />
                    </View>
        );
    }

I just want to put button in form. How to make it?


Solution

  • this way:

     buttoncoordinate:{
                label:'',
                stylesheet : textInput,
                factory: YoutButtonComponent
               }
    

    For example:

    var options = {
      fields: {
        name: {
          factory: MyComponent
        }
      }
    };