如何在 ExtJs 文本字段中显示大写值而不显示用户字母从小写到大写的转换?
我们正在使用 ExtJS 4 创建一个应用程序,该应用程序要求表单文本字段中的条目应始终为大写。
为此,我发现我可以在更改事件上调用函数,并将当前值转换为大写,然后按以下方式将其设置回字段:
change: function(field, newValue){
field.setValue(newValue.toUpperCase());
}
这样做的作用是,如果用户输入小写字母,则会将其转换改为大写并将其放回字段中。在此期间,会向用户显示从小写到大写的轻微过渡。也就是说,用户能够看到小写字母,并且可能在一毫秒之后,该字母变成大写字母。
问题是:有没有办法避免这种从小写到大写的“转换/转换”,并在用户输入内容后立即向用户显示大写字母?
我尝试使用 - style=文本转换:大写 - 但没有运气。
任何帮助将不胜感激。
提前致谢。
We are creating an application using ExtJS 4 which has a requirement that entry in a form textfield should always be in UPPERCASE.
For this, I found that I can call a function on change event and convert the current value to uppercase and set it back to the field in following way:
change: function(field, newValue){
field.setValue(newValue.toUpperCase());
}
What this does is that if a user enters a letter in lowercase, then it converts it to uppercase and puts it back in the field. During this, there is a slight transition displayed to the user from lower to upper case. That is, the user is able to see the letter in lower case and after a millisecond may be, the letter becomes uppercase.
The question is: Is there a way to avoid this 'transition/transformation' from lower to upper case and show letters in uppercase directly to the user as soon as he types something?
I tried using - style=text-transform:uppercase - but no luck.
Any help would be really appreciated.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该使用
fieldStyle< /code>
相反。 这里是演示。
干杯!
You should have used
fieldStyle
instead. Here is demo.Cheers!
给定的答案仅适用于以大写形式显示文本,但值保持不变。我扩展了文本字段以覆盖 getValue() 方法,以返回大写的值,不仅用于显示,还带有可选的配置标志:
然后我可以轻松地将多个文本字段添加到表单中:
适用于 EXT 4.2.1。
The given answer works only for DISPLAYING the text in uppercase, but the value remains the same. I've extended the textfield to override the getValue() method to return the value in uppercase, not only for displaying, with an optional config flag:
Then I can easily add several textfields to a form:
Works in EXT 4.2.1.
您也可以使用插件来完成。
在 ExtJS 4.2.1 中使用此插件
灵感来自:https://www.sencha.com/forum/showthread.php?94599-Uppercase-TextField-plugin&p=522068&viewfull=1#post522068
PS:我必须在原型上调用 getValue。如果我在 cmp 上调用 getValue,它将递归地继续执行此操作并且永远不会退出。我愿意接受有关如何通过插件更改组件的 getValue 方法的建议。
You can do it with a plugin too.
Using this as the plugin in ExtJS 4.2.1
Inspired by: https://www.sencha.com/forum/showthread.php?94599-Uppercase-TextField-plugin&p=522068&viewfull=1#post522068
PS: I had to call getValue on the prototype. If I would have called getValue on the cmp it would recursively continue to do that and never exit. I'm open to suggestions on how to change the component's getValue method through the plugin.
它适用于 ExtJS 4.2
如果您只想为文本字段输入大写字母,则扩展基本文本字段以将字段样式更改为大写,并附加一个侦听器以将任何文本更改为大写时更新原始值。
//定义一个新的自定义文本字段
//使用别名在视图定义中使用新创建的自定义文本字段
It Works for ExtJS 4.2
If you want only uppercase input for your text field then extend the base text field to change the field style to uppercase and also attach a listener to update the raw value on any text change to uppercase.
//define a new custom text field
//use the newly created custom text field in your view definition using the alias