Everything is ok if I use Ant Design TreeSelect component in form like this:
<Form.Item>
{getFieldDecorator('geo_objects_value', {
rules: [{
required: true,
message: 'Warning msg'
}],
})(
<TreeSelect
treeData={treeGeoObjects}
treeNodeFilterProp={'title'}
treeCheckable={true}
allowClear
showCheckedStrategy={SHOW_PARENT}
dropdownStyle={{maxHeight: 500, overflow: 'auto'}}
/>
)}
</Form.Item>
But if I try to use a custom class with the Ant Design Tree component, it will give a warning message: that means the value has not been received.
My custom class:
class Demo extends React.Component {
constructor(props) {
super(props);
this.treeData = props.treeData;
this.state = {
expandedKeys: [],
autoExpandParent: true,
value: [],
};
}
onExpand = expandedKeys => {
this.setState({
expandedKeys,
autoExpandParent: false,
});
};
onCheck = value => {
this.setState({value});
this.props.value = value;
console.log('onCheck', this.props.value);
};
renderTreeNodes = data =>
data.map(item => {
if (item.children) {
return (
<TreeNode title={item.title} key={item.key} dataRef={item}>
{this.renderTreeNodes(item.children)}
</TreeNode>
);
}
return <TreeNode key={item.key} {...item} />;
});
render() {
return (
<Tree
checkable
onExpand={this.onExpand}
expandedKeys={this.state.expandedKeys}
autoExpandParent={this.state.autoExpandParent}
onCheck={this.onCheck}
checkedKeys={this.state.value}
>
{this.renderTreeNodes(this.treeData)}
</Tree>
);
}
}
Using custom class inside the form:
<Form.Item>
{getFieldDecorator('geo_objects_value', {
rules: [{
required: true,
message: 'Warning msg'
}],
})(
<Demo treeData={treeGeoObjects}/>
)}
</Form.Item>
What am I doing wrong? Why can't getFieldDecorator get the value from my class? Please help!