]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * The Password field creates a password input and is usually created inside a form. Because it creates a password\r | |
3 | * field, when the user enters text it will show up as stars. Aside from that, the password field is just a normal text\r | |
4 | * field. Here's an example of how to use it in a form:\r | |
5 | *\r | |
6 | * @example\r | |
7 | * Ext.create('Ext.form.Panel', {\r | |
8 | * fullscreen: true,\r | |
9 | * items: [\r | |
10 | * {\r | |
11 | * xtype: 'fieldset',\r | |
12 | * title: 'Register',\r | |
13 | * items: [\r | |
14 | * {\r | |
15 | * xtype: 'emailfield',\r | |
16 | * label: 'Email',\r | |
17 | * name: 'email'\r | |
18 | * },\r | |
19 | * {\r | |
20 | * xtype: 'passwordfield',\r | |
21 | * label: 'Password',\r | |
22 | * name: 'password'\r | |
23 | * }\r | |
24 | * ]\r | |
25 | * }\r | |
26 | * ]\r | |
27 | * });\r | |
28 | *\r | |
29 | * Or on its own, outside of a form:\r | |
30 | *\r | |
31 | * Ext.create('Ext.field.Password', {\r | |
32 | * label: 'Password',\r | |
33 | * value: 'existingPassword'\r | |
34 | * });\r | |
35 | *\r | |
36 | * Because the password field inherits from {@link Ext.field.Text textfield} it gains all of the functionality that text\r | |
37 | * fields provide, including getting and setting the value at runtime, validations and various events that are fired as\r | |
38 | * the user interacts with the component. Check out the {@link Ext.field.Text} docs to see the additional functionality\r | |
39 | * available.\r | |
40 | */\r | |
41 | Ext.define('Ext.field.Password', {\r | |
42 | extend: 'Ext.field.Text',\r | |
43 | xtype: 'passwordfield',\r | |
44 | alternateClassName: 'Ext.form.Password',\r | |
45 | \r | |
46 | config: {\r | |
47 | /**\r | |
48 | * @cfg autoCapitalize\r | |
49 | * @inheritdoc\r | |
50 | */\r | |
51 | autoCapitalize: false,\r | |
52 | \r | |
53 | /**\r | |
54 | * @cfg revealable {Boolean}\r | |
55 | * Enables the reveal toggle button that will show the password in clear text. This is currently only implemented in the Blackberry theme\r | |
56 | */\r | |
57 | revealable: false,\r | |
58 | \r | |
59 | /**\r | |
60 | * @cfg revealed {Boolean}\r | |
61 | * A value of 'true' for this config will show the password from clear text\r | |
62 | */\r | |
63 | revealed: false,\r | |
64 | \r | |
65 | /**\r | |
66 | * @cfg component\r | |
67 | * @inheritdoc\r | |
68 | */\r | |
69 | component: {\r | |
70 | type: 'password'\r | |
71 | }\r | |
72 | },\r | |
73 | \r | |
74 | isPassword: true,\r | |
75 | \r | |
76 | initialize: function() {\r | |
77 | this.callParent(arguments);\r | |
78 | this.addCls(Ext.baseCSSPrefix + 'field-password');\r | |
79 | },\r | |
80 | \r | |
81 | updateRevealable: function(newValue, oldValue) {\r | |
82 | if (this.$revealIcon) {\r | |
83 | this.getComponent().element.removeChild(this.$revealIcon);\r | |
84 | this.$revealIcon = null;\r | |
85 | }\r | |
86 | \r | |
87 | if(newValue === true) {\r | |
88 | this.$revealIcon = new Ext.Element(Ext.Element.create({cls:'x-reveal-icon'}, true));\r | |
89 | this.$revealIcon.on({\r | |
90 | tap: 'onRevealIconTap',\r | |
91 | touchstart: 'onRevealIconPress',\r | |
92 | touchend: 'onRevealIconRelease',\r | |
93 | scope: this\r | |
94 | });\r | |
95 | this.getComponent().element.appendChild(this.$revealIcon);\r | |
96 | }\r | |
97 | },\r | |
98 | \r | |
99 | updateRevealed: function(newValue, oldValue) {\r | |
100 | var component = this.getComponent();\r | |
101 | \r | |
102 | if(newValue) {\r | |
103 | this.element.addCls(Ext.baseCSSPrefix + 'revealed');\r | |
104 | component.setType("text");\r | |
105 | } else {\r | |
106 | this.element.removeCls(Ext.baseCSSPrefix + 'revealed');\r | |
107 | component.setType("password");\r | |
108 | }\r | |
109 | },\r | |
110 | \r | |
111 | /**\r | |
112 | * @private\r | |
113 | */\r | |
114 | updateValue: function(value, oldValue) {\r | |
115 | this.toggleRevealIcon(this.isValidTextValue(value));\r | |
116 | this.callParent([value, oldValue]);\r | |
117 | },\r | |
118 | \r | |
119 | doKeyUp: function(me, e) {\r | |
120 | var value = me.getValue(),\r | |
121 | valid = me.isValidTextValue(me.getValue());\r | |
122 | \r | |
123 | me.toggleClearIcon(valid);\r | |
124 | \r | |
125 | if (e.browserEvent.keyCode === 13) {\r | |
126 | me.fireAction('action', [me, e], 'doAction');\r | |
127 | }\r | |
128 | \r | |
129 | me.toggleRevealIcon(valid);\r | |
130 | },\r | |
131 | \r | |
132 | /**\r | |
133 | * @private\r | |
134 | */\r | |
135 | showRevealIcon: function() {\r | |
136 | var me = this,\r | |
137 | value = me.getValue(),\r | |
138 | // allows value to be zero but not undefined or null (other falsey values)\r | |
139 | valueValid = value !== undefined && value !== null && value !== "";\r | |
140 | \r | |
141 | if (me.getRevealable() && !me.getDisabled() && valueValid) {\r | |
142 | me.element.addCls(Ext.baseCSSPrefix + 'field-revealable');\r | |
143 | }\r | |
144 | \r | |
145 | return me;\r | |
146 | },\r | |
147 | \r | |
148 | /**\r | |
149 | * @private\r | |
150 | */\r | |
151 | hideRevealIcon: function() {\r | |
152 | if (this.getRevealable()) {\r | |
153 | this.element.removeCls(Ext.baseCSSPrefix + 'field-revealable');\r | |
154 | }\r | |
155 | },\r | |
156 | \r | |
157 | onRevealIconTap: function(e) {\r | |
158 | this.fireAction('revealicontap', [this, e], 'doRevealIconTap');\r | |
159 | },\r | |
160 | \r | |
161 | /**\r | |
162 | * @private\r | |
163 | */\r | |
164 | doRevealIconTap: function(me, e) {\r | |
165 | me.setRevealed(!this.getRevealed());\r | |
166 | },\r | |
167 | \r | |
168 | onRevealIconPress: function() {\r | |
169 | this.$revealIcon.addCls(Ext.baseCSSPrefix + 'pressing');\r | |
170 | },\r | |
171 | \r | |
172 | onRevealIconRelease: function() {\r | |
173 | this.$revealIcon.removeCls(Ext.baseCSSPrefix + 'pressing');\r | |
174 | },\r | |
175 | \r | |
176 | privates: {\r | |
177 | isValidTextValue: function(value) {\r | |
178 | // allows newValue to be zero but not undefined or null (other falsey values)\r | |
179 | return (value !== undefined && value !== null && value !== '');\r | |
180 | },\r | |
181 | \r | |
182 | toggleRevealIcon: function(state) {\r | |
183 | if (state) {\r | |
184 | this.showRevealIcon();\r | |
185 | } else {\r | |
186 | this.hideRevealIcon();\r | |
187 | }\r | |
188 | }\r | |
189 | }\r | |
190 | });\r |