0

我想将按钮放入表单中以获取当前位置,然后将值放入坐标中

我试过了,但它不起作用

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>
        );
    }

我只想把按钮放在表单中。怎么做?

4

2 回答 2

1

这边走:

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

例如:

var options = {
  fields: {
    name: {
      factory: MyComponent
    }
  }
};
于 2019-09-10T16:39:53.133 回答
0

更改代码。按钮不是输入,也不能在选项中使用。

<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>
于 2019-09-10T10:54:42.130 回答