How to input button in tcomb react native

178 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 answers

0
Oleg On BEST ANSWER

this way:

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

For example:

var options = {
  fields: {
    name: {
      factory: MyComponent
    }
  }
};
0
Oleg 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>