Ant-design: Is there a way to make my custom Select reconized by "getFieldValue"?

Created on 24 Aug 2017  ·  1Comment  ·  Source: ant-design/ant-design

What problem does this feature solve?

"this.props.forms.getFieldValue" can help me to reduce the unnecessary controlled code. But it cannot be applied to custom input compoenent.

I make a simple custom select compoenent——none styles be changed,just some code about data fetch and handle in "componentDidMount".

But it seems cannot be reconized by "this.props.forms.getFieldValue". So I had to make it to be a controlled component and add some simple , tedious code .

What does the proposed API look like?

class CustomSelect extends React.Component {
   constructor(props){...}

    getFieldValue() {
        return this.state.value
    }

    setFieldName(name) {
        this.setState({name: name})
    }

    getFieldName(name) {
        return this.state.name
    }

    render() {
        <Select
            onChange={value=>this.setState(value:value)}
        >... </Select>
    }
}

the custome component will be accessed by "this.props.forms.getFieldValue" just like any other antd Input component via the interface provided by antd.
If there's any problem in the issue , please let me know.
regards.

Most helpful comment

https://ant.design/components/form/#components-form-demo-customized-form-controls

>All comments

https://ant.design/components/form/#components-form-demo-customized-form-controls

Was this page helpful?
0 / 5 - 0 ratings