input-number icon indicating copy to clipboard operation
input-number copied to clipboard

onBlur 里做校验时,无法拿到 format 后的 value 值

Open promise96319 opened this issue 2 years ago • 1 comments

代码如下:

<InputNumber
  precision={0}
  onBlur={() => console.log('blur')}
  onChange={() => console.log('change')}
/>

当使用 precision 时,如果输入的内容不符合当前精度((比如 0.9),此时失焦,会先触发 onBlur,拿到的 value 值为 0.9。然后 InputNumber 组件再将 value 值格式化,触发 onChange, 此时拿到的 value 值是 1。

在业务中,如果在 onBlur 中去做校验,无法拿到最终格式化后的值。需要通过异步去获取,感觉不是很好,是否能在 onBlur 里将值直接格式化后再出发外层 onBlur 事件?

历史版本有相关 issue 和解决,但是最新版似乎没有。

  • (https://github.com/react-component/input-number/issues/325
  • https://github.com/react-component/input-number/pull/190

promise96319 avatar Mar 01 '23 06:03 promise96319

Hello, we are having a similar problem to this.

bombillazo avatar Nov 02 '23 13:11 bombillazo