I know type=number works but that is not what i want. my HTML:
<FormItem style={{ display: "inline-block" }}>
{getFieldDecorator('matchPercentage', {
initialValue: this.state.matchPercentage
})(
<Input type="number" value={this.state.matchPercentage} onChange={this.handlePercentMatch} style={{ width: 100, marginLeft: 10 }} />
)}
</FormItem>
my Function:
handlePercentMatch = (e) => {
const isInteger = /^[0-9]+$/;
if (e.target.value === '' || isInteger.test(e.target.value)) {
this.setState({ matchPercentage: e.target.value })
}
}
My isInteger.test()
is working meaning I am able to get only integers in matchPercentage
in state. But the problem is It is not reflecting in GUI. I am still able to type alphabets even though they are not being set into state.
I know type="number" works but that is not what i want. I want to validate using react as i want control decimals and upto how many digits and non negative
I have added my code here https://codepen.io/DadyByte/pen/xYgLvy?editors=1010
I found the root cause. If you use
FormItem
you will be allowed to type no matter what. If I useInput
outside FormItem my code is working. What can I do to prevent it