[英]Use react-input-mask with antd in react-final-form
[英]Update the value on input blur in react-final-form
我正在使用react-number-format
和react-final-form
。 我的組件如下所示:
const CurrencyInput = props => {
return (
<NumberFormat
thousandSeparator=" "
decimalScale="2"
isNumericString={true}
fixedDecimalScale={true}
allowNegative={false}
autoComplete="off"
onBlur={props.input.onBlur}
onFocus={props.input.onFocus}
onChange={value => props.input.onChange(value)}
/>
);
};
react-number-format
具有allowLeadingZeros
,它在輸入模糊時去除前導零。 如何相應地更新react-final-form
中的值? 如果我在數字前輸入零,則輸入本身的值會在模糊時得到糾正,但react-final-form
存儲的值將保持為零。
這是我的代碼框。
格式化字符串后, react-number-format
不會調用 onChange。
但是react-number-format
有一個名為onValueChange
的道具,它在格式化字符串后被觸發:
示例: https://codesandbox.io/s/react-final-form-wreact-number-format-bmeg9
除此之外,我建議將值存儲為 state 中的數字而不是字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.