Skip to content

Commit b33c59c

Browse files
committed
Password input with eye icon to show plaintext
1 parent 7182e44 commit b33c59c

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

PasswordInput.png

4.99 KB
Loading

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ new \Ease\ui\SignInForm();
103103
![Sign In](https://raw.githubusercontent.com/VitexSoftware/Ease-PHP-Bricks/master/SignIn.png "Sign In form")
104104

105105

106+
Password Input
107+
--------------
108+
109+
With eye icon to show plaintext
110+
111+
```php
112+
new PasswordInput($this->passwordField);
113+
```
114+
![Password Input](https://raw.githubusercontent.com/VitexSoftware/Ease-PHP-Bricks/master/PaswordInput.png "Password input")
115+
116+
106117
Installation
107118
------------
108119

nbproject/project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<type>org.netbeans.modules.php.project</type>
44
<configuration>
55
<data xmlns="http://www.netbeans.org/ns/php-project/1">
6-
<name>EasePHPbricks</name>
6+
<name>EasePHP Bricks</name>
77
</data>
88
</configuration>
99
</project>

src/Ease/ui/PasswordInput.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/*
3+
* To change this license header, choose License Headers in Project Properties.
4+
* To change this template file, choose Tools | Templates
5+
* and open the template in the editor.
6+
*/
7+
8+
namespace Ease\ui;
9+
10+
/**
11+
* Description of PasswordInput
12+
*
13+
* @author Vítězslav Dvořák <[email protected]>
14+
*/
15+
class PasswordInput extends \Ease\Html\DivTag
16+
{
17+
18+
/**
19+
* Password input
20+
*
21+
* @param string $name Input name
22+
* @param string $value Plaintext password
23+
* @param array $properties Poroperties for password input
24+
*/
25+
public function __construct($name, $value = null,$properties = [])
26+
{
27+
$inpass = new \Ease\Html\InputPasswordTag($name, $value);
28+
$inpass->setTagID();
29+
$inpass->setTagProperties($properties);
30+
parent::__construct($inpass, ['class' => 'input-group']);
31+
$this->addItem(new \Ease\Html\SpanTag(null,
32+
['id' => $inpass->getTagID().'eye', 'toggle' => '#password-field', 'class' => 'glyphicon glyphicon glyphicon-eye-open']));
33+
$this->addJavaScript('
34+
$("#'.$inpass->getTagID().'eye").click(function() {
35+
$("#'.$inpass->getTagID().'eye").toggleClass("glyphicon-eye-open glyphicon-eye-close");
36+
var input = $("#'.$inpass->getTagID().'");
37+
if (input.attr("type") == "password") {
38+
input.attr("type", "text");
39+
} else {
40+
input.attr("type", "password");
41+
}
42+
});
43+
');
44+
}
45+
}

src/Ease/ui/SignInForm.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@
1414
*/
1515
class SignInForm extends \Ease\TWB\Form
1616
{
17+
/**
18+
*
19+
* @var string
20+
*/
1721
public $userNameField = 'username';
18-
public $passwordField = 'passwoerd';
22+
/**
23+
*
24+
* @var string
25+
*/
26+
public $passwordField = 'password';
1927

2028
public function __construct($formAction = null, $formMethod = 'post',
2129
$tagProperties = null)
@@ -24,7 +32,7 @@ public function __construct($formAction = null, $formMethod = 'post',
2432
$tagProperties);
2533
$this->addInput(new \Ease\Html\InputTextTag($this->userNameField),
2634
_('Username'), _('Login'));
27-
$this->addInput(new \Ease\Html\InputPasswordTag($this->passwordField),
35+
$this->addInput(new PasswordInput($this->passwordField),
2836
_('Password'), '');
2937
}
3038

0 commit comments

Comments
 (0)