class MyComponent extends Component {
submit = () => {
this.props.form.validateFields((error, value) => {
if (error != undefined) {
console.error(error);
}
console.log(value);
});
}
render() {
return <div>
<InputItem {...getFieldProps("input1")} >文本框</InputItem>//这个能取到值
<MixedInput {...getFieldProps('input2')}>自定义组件</MixedInput>//这个取到值是undefined
</div>
}
}
export default createForm()(MyComponent)
rc-form要求组件必须具有value和onChange
getFieldProps(name, option): Object { [valuePropName], [trigger], [validateTrigger] }
Will create props which can be set on a input/InputComponent which support value and onChange interface.
After set, this will create a binding with this input.
MixedInput是我自定义的组件
class MixedInput extends Component {
value = () => {
return "xxx"
}
onChange = () => {
console.log("set value")
this.setState({ value: 'xxx' });
}
render() {
let options = this.props.items.map(function (option, idx) {
return { value: option.value, label: option.text }
});
return (
<div>
<Picker data={options} cols={1} onChange={this.onChange}>
<List.Item>{this.props.label}</List.Item>
</Picker>
<TextareaItem rows={3} onChange={this.onChange} />
</div>
)
}
}
export default MixedInput
这样设置并不能起作用,在submit获取到的属性值始终是undefined,哪位大神麻烦告诉我自定义组件rc-form的使用,感激不尽
侃侃无极
慕斯王
慕田峪7331174
相关分类