i cannot able to set value to the Inputfield in Form. below is my code. even i tried to give direct value too like in value='ABC'
in input element. but no luck. when i tried to display value outside Form Tag like
<h1>{this.state.company.companyCode}</h1>
this shows value. but not inside Form.
class UpdateCompany extends Component {
constructor(props) {
super(props);
this.state = {
companycode: { value: ''},
company: ''
};
this.loadCompanydetail = this.loadCompanydetail.bind(this);
}
loadCompanydetail(companyid) {
GetCompanyById(companyid)
.then(response => {
this.setState({
company: response
});
}).catch(error => {
if(error.status === 404) {
this.setState({
notFound: true,
isLoading: false
});
} else {
this.setState({
serverError: true,
isLoading: false
});
}
});
}
componentDidMount(){
const companyid =this.props.match.params.companyId;
this.loadCompanydetail(companyid);
}
render() {
const { getFieldDecorator } = this.props.form
return (
<h1 className="page-title">Edit Company - {this.state.company.companyCode}</h1>
<Form>
<Form.Item label="Company Code">
{getFieldDecorator('companycode', {
rules: [
{
required: true,
message: 'Please enter Code',
max: 3,
},
],
})(<Input name="companycode" value={this.state.company.companyCode} />)}
</Form.Item>
<Form.Item wrapperCol={{ span: 12, offset: 6 }}>
<Button type="primary"
htmlType="submit"
size="large">Submit</Button>
</Form.Item>
</Form>
);
}
}