如何在 Ext.form.TextField 中显示/隐藏密码
您能告诉我如何在单击另一个按钮时显示/隐藏密码字段的输入文本吗?!我尝试更改该文本字段的 inputType 属性,但它是在当时渲染的,因此没有影响。另一种方法是创建 2 个文本字段并使其可见/不可见,但我不喜欢这样做,因为它看起来像作弊...... 提前致谢。
could you please show me the solution to make the input text of password field show/hide when clicking another button?! I've tried to change the inputType property of that textfield, but it was rendered at that time so it didn't affect. Another way is create 2 textfields and visbile/invisible them, but I don't like do this, because it looks like cheating...
Thank in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,这篇文章有点旧了,但我想我还是会回答它。也许它会帮助别人。
您是正确的,在渲染项目后,它的类型已在 DOM 中设置为“密码”。因此我们需要直接操作 DOM。假设我的窗口有 1 个项目(一个 FormPanel),并且此 FormPanel 中有 1 个项目(一个文本字段)。我最初在配置选项中将其设置为 inpupType: 'password' 。现在我想改变这一点。这是我要做的:
this.get(0).getForm().get(1).getEl().dom.type = 'text'
(我假设这是在一个具有我的范围的事件处理程序中窗口)
这将更改 DOM 并立即将我的密码显示为文本。要将其改回来:
this.getForm().get(1).getEl().dom.type = 'password'
在现实世界中,我不会使用 get(index),而是为文本字段设置一个名称并使用 find,否则我会创建一个指向文本字段的 var。
希望这对某人有帮助。
瑞奇
Well this post is a little old, but I thought I'd answer it anyway. Maybe it will help someone else.
You are correct that after the item is rendered it's type has been set to 'password' in the DOM. Thus we need to directly manipuate the DOM. Let's say I window that has 1 item, a FormPanel, and I have 1 item in this FormPanel, a textfield. I initially set it's inpupType: 'password' in my config options. Now I want to change that. Here is what I would do:
this.get(0).getForm().get(1).getEl().dom.type = 'text'
(I assume that this is in an event handler that has the scope of my window)
That will change the DOM and immediately show my password as text. To change it back:
this.getForm().get(1).getEl().dom.type = 'password'
In a real world situation I would not use get(index), but either set a name for the textfield and use find, or I would create a var that points to the textfield.
Hope this helps someone.
Ricky
是的,我也偶然发现了这一点。在深入研究网络之后,我感觉很糟糕,因为在 ext 框架中没有内置的方法可以做到这一点,尽管现在它已成为更常见的要求。
在其他人建议的帮助下,我实施了以下建议。
小提琴在这里 https://fiddle.sencha.com/#view/editor&fiddle /25平方米
Yes,I too stumbled upon this. After digging in web I felt bad as there is no built in way to do this in the ext framework though it became more common requirement now days.
With the help of other people suggestions I implemented below one.
Fiddle is here https://fiddle.sencha.com/#view/editor&fiddle/25m2