How to input button in tcomb react native

188 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

this way:

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

For example:

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

change the code. Button is not input and not be used in options.

<View style={styles.formInput}>
                        <Form
                            ref="form"
                            type={validForm}
                            options={options}
                            value={this.state.value}
                            onChange={this._onChange}
                        />
               <Button block onPress={() => this.login()}>
               <Text>Login</Text>
               </Button>
                    </View>