'form.setFieldsValue render not true in onChange event
I have a problem when setFieldsValue. This is my code:
<Form.Item>
{
form.getFieldDecorator('value_of_type', {
initialValue: 3
})(
<InputNumber
type='number'
onChange={value => this.truncateInputNumber(value)}
/>)
}
</Form.Item>
truncateInputNumber function:
truncateInputNumber = (value) => {
const {form} = this.props;
const newValue = Math.floor(value*Math.pow(10,3))/(Math.pow(10,3));
form.setFieldsValue({
value_of_type: newValue
});
console.log(form.getFieldValue("value_of_type"));
return newValue
}
When i type "12,34567" to Input, console.log form.getFieldValue("value_of_type") in truncateInputNumber function, result is true (12,345) but in render, result is false (12,34567).
I don't know why in render function form.getFieldValue("value_of_type") return false result.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
