We should always trigger ngModelChange when typing. If developers want to update model value only on blur, they can easily use ngModelOptions to specify its behavior.
我觉得我们应该在用户输入时始终触发 ngModelChange 事件。如果开发者希望在 blur 时才触发更新,可以简单的通过设置 ngModelOptions 指定。
But now we hardcoded its behavior, developers cannot change its behavior back. We use input-number to input integers for most situations, (input) events work fine for those cases.
但是现在在代码中强制了这种行为,用户却无法改回默认的 input 触发。input-number 大多数还是用于输入整数的情况;input 事件对于这种情况工作良好。
Now the behavior is very strange for nonempty validation. The submit button keeps disabled state after user typed some number.
现在做表单的非空验证时行为很奇怪。用户输入了值,提交按钮还是禁用不能点击的状态。
Ref: https://github.com/NG-ZORRO/ng-zorro-antd/issues/2708
Trigger ngModelChange event when users' typing
I would have thought that I could easily workaround this issue by reverting back to native input[type=number], but I happened to find the bug
Any plan to implement this feature? @vthinkxie
目前的设计是无法实现在输入时立刻trigger的,否则所有的符号都不可能正常输入
当你输入 -0.01 的时候,你的 ngModelChange 得到的结果会是
undefined,由于双向绑定,输入的 - 会直接消失掉
同样,小数输入和其他格式化输入(即使是正整数,比如 1e10)也会变成完全不可能实现的情况,因为 0. 和 1e 在实时校验的时候也是非法字符,在你输入的时候会被立刻重置掉
输入1e10这种毕竟是少数情况。我的建议是提供配置让用户选择使用,不要写死。
其实我的建议是:重置这个操作在blur时做,验证在input时做(如果是非法状态只是显示红框而不是重置)
非法状态是根据当前的ngModel或者formControl的实际数值决定的,能够显示非法状态也就意味着当前的值已经被改变了,在目前的 angular 的 form 设计下实现不了的
表单的提交按钮可以设计成一直可点击状态,当点击时提示用户填错项内容
用blur很不方便,其实很多平台保存按钮的状态就是随着输入改变的,非得输入完之后点一下其他地方,这个体验就不好。另外blur中不能直接传当前value啊,$event是undefined
添加配置项让用户选择就好了,这样就不会有争议
Any update on this? Please leave the decision to users, ngModelOptions already have this option.
Please consider this. We should not lock out developers to use a functionality because of a possible problem on float since it works correctly on integer. Furthermore, developers could use ngModelOptions to use this behaviour whenever they need to.
Hi all, this issue will be fixed after ng-zorro-antd v9 released
Most helpful comment
Hi all, this issue will be fixed after ng-zorro-antd v9 released