Roo/form/Password.js
authorleon <leon@roojs.com>
Fri, 22 Dec 2023 03:39:12 +0000 (11:39 +0800)
committerleon <leon@roojs.com>
Fri, 22 Dec 2023 03:39:12 +0000 (11:39 +0800)
Roo/form/Password.js [new file with mode: 0644]

diff --git a/Roo/form/Password.js b/Roo/form/Password.js
new file mode 100644 (file)
index 0000000..6ab6f38
--- /dev/null
@@ -0,0 +1,50 @@
+Roo.form.Password = function(config){
+    Roo.form.Password.superclass.constructor.call(this, config);
+
+    this.inputType = 'password';
+};
+
+Roo.extend(Roo.form.Password, Roo.form.TextField,  {
+    onRender : function(ct, position)
+    {
+        Roo.bootstrap.form.SecurePass.superclass.onRender.call(this, ct, position);
+
+        this.el.addClass('form-password');
+
+        this.wrap = this.inputEl().wrap({
+            cls : 'password-wrap'
+        });
+
+        this.toggle = this.wrap.createChild({
+            tag : 'Button',
+            cls : 'password-toggle'
+        });
+
+
+        this.toggleEl().addClass('password-hidden');
+
+        this.toggleEl().on('click', this.onToggleClick, this);;
+    },
+
+    toggleEl: function()
+    {
+        return this.el.select('button.password-toggle',true).first();
+    },
+
+    onToggleClick : function(e) 
+    {
+        var input = this.inputEl();
+        var toggle = this.toggleEl();
+
+        toggle.removeClass(['password-visible', 'password-hidden']);
+
+        if(input.attr('type') == 'password') {
+            input.attr('type', 'text');
+            toggle.addClass('password-visible');
+        }
+        else {
+            input.attr('type', 'password');
+            toggle.addClass('password-hidden');
+        }
+    }
+}
\ No newline at end of file