Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<InputNumber /> onChange 事件触发后表现不一致 #4265

Closed
ystarlongzi opened this issue Dec 15, 2016 · 22 comments · Fixed by react-component/input-number#41
Closed

<InputNumber /> onChange 事件触发后表现不一致 #4265

ystarlongzi opened this issue Dec 15, 2016 · 22 comments · Fixed by react-component/input-number#41
Assignees
Labels
🐛 Bug Ant Design Team had proved that this is a bug.

Comments

@ystarlongzi
Copy link
Contributor

<InputNumber /> 组件在触发 onChange 事件时表现不一致,导致在 onBlur 事件里可能无法获取到最新的状态。

如下图,查看demo

111

是否可以考虑在mixin.js#L76加个定时器,避免这种现象?

@luckyyang
Copy link

这里还有一个bug。如果我不blur,直接在input框中输入 1 然后点击提交按钮,目前是不会触发传给form的onFieldsChange的,在redux也无法拿到当前的输入值。 @afc163

@benjycui
Copy link
Contributor

点击提交按钮是,应该会触发 blur 的。

@luckyyang
Copy link

luckyyang commented Dec 22, 2016

我的按钮没有放到form组件中,并没有触发。onFieldsChange中接收不到值,手动的onBlur是可以在onFieldsChange中接收到值的 @benjycui

@afc163 afc163 reopened this Dec 22, 2016
@afc163
Copy link
Member

afc163 commented Dec 22, 2016

@luckyyang 最好给个最简的在线例子方便重现和调试,我看你的文字描述貌似有点自相矛盾。

http://codepen.io/benjycui/pen/KgPZrE?editors=001

@luckyyang
Copy link

@afc163 你们有redux的模板么,我是在redux项目中发现这个问题的。

我看到blur确实被触发了,redux也接收到了变化后的值。只是问题是,我提交按钮按下后,无法保证使用的值是变化后的值

@luckyyang
Copy link

luckyyang commented Jan 4, 2017

另外,为什么不让InputNumber也触发onChange事件呢? 如果触发onChange 事件,就不会有这个问题了

@afc163
Copy link
Member

afc163 commented Jan 5, 2017

因为有可能输入非数字,InputNumber 目前的实现是 onChange 只输出数字值,非数字输入在 blur 时会清除。

@luckyyang
Copy link

而实际情况是,直接手动输入值,并不会触发onChange。用户会认为这个是bug

@afc163
Copy link
Member

afc163 commented Jan 5, 2017

手动输入后,blur 时才会触发 onChange。

@luckyyang
Copy link

我看到blur确实被触发了,redux也接收到了变化后的值。只是问题是,我提交按钮按下后,无法保证使用的值是变化后的值

请问这样的情况如何解决呢

@afc163
Copy link
Member

afc163 commented Jan 5, 2017

提交按钮按下前,InputNumber 的 blur 是会先触发的,我本地测试了『用户手动输入数值 + 然后直接点击确定按钮』能拿到。你的问题能否尝试给我个重现,方便调试和修复。

@luckyyang
Copy link

要复现的话,我需要单独做一个项目出来,稍等等

@afc163
Copy link
Member

afc163 commented Jan 5, 2017

麻烦了。

@afc163
Copy link
Member

afc163 commented Jan 17, 2017

升级了 rc-input-number,修正成用户输入,blur 时都会触发 onChange。

@ystarlongzi
Copy link
Contributor Author

@afc163
升级后,如果输入非数字,然后在失去焦点时,文本框内容会为空。如下图,为官方demo截图:
111

@luckyyang
Copy link

luckyyang commented Jan 17, 2017

@afc163 👍 你们啥时候升级antd ? 我觉得这样才好,也省的我发那个麻烦的redux demo了

afc163 added a commit to react-component/input-number that referenced this issue Jan 17, 2017
@pastelsky
Copy link
Contributor

pastelsky commented Jan 24, 2017

@afc163 Why is this closed? Even though rc-input-number (v3.0.0) has fixed the bug, the latest version of antd still points to ~v2.8.3.

Could you please bump up the version number?

@afc163
Copy link
Member

afc163 commented Jan 24, 2017

That will be released in 2.7.0 before Chinese new year: 2017-01-27

@pastelsky
Copy link
Contributor

Thanks a lot.

@pastelsky
Copy link
Contributor

@afc163 Sorry to bug you again with this, but antd has moved to 2.7.0 a couple of days back, but the latest on npm is still 2.6.4. Is something holding up the release?

@afc163
Copy link
Member

afc163 commented Feb 2, 2017

@RaoHai We can release 2.7.0 now.

@lock
Copy link

lock bot commented May 2, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 2, 2018
Superdev0103 added a commit to Superdev0103/react-input-number that referenced this issue Jan 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐛 Bug Ant Design Team had proved that this is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants