1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AntonyThorpe\Knockout; |
4
|
|
|
|
5
|
|
|
require_once('Common.php'); |
6
|
|
|
use SilverStripe\Forms\PasswordField; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* KnockoutPasswordField |
10
|
|
|
* |
11
|
|
|
* Creates a {@link PasswordField} with an additional data-bind attribute that links to a Knockout obervable |
12
|
|
|
* @uses 'password' as the default observable |
13
|
|
|
*/ |
14
|
|
|
class KnockoutPasswordField extends PasswordField |
15
|
|
|
{ |
16
|
|
|
use \AntonyThorpe\Knockout\Common; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* bindingType |
20
|
|
|
* |
21
|
|
|
* KnockoutPasswordField needs either 'value' or 'textInput' as a key for the 'data-bind' HTML attribute |
22
|
|
|
* |
23
|
|
|
* @var string data-bind attribute key |
24
|
|
|
* @example data-bind="input: name, valueUpdate: 'input'" - the binding type is: input. |
25
|
|
|
*/ |
26
|
|
|
protected $bindingType = "textInput"; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* casting of variables for security purposes |
30
|
|
|
* |
31
|
|
|
* @see http://docs.silverstripe.org/en/3.1/developer_guides/security/secure_coding/ |
32
|
|
|
*/ |
33
|
|
|
protected $casting = array( |
34
|
|
|
"Observable" => "Varchar", |
35
|
|
|
"BindingType" => "Varchar", |
36
|
|
|
"OtherBindings" => "Varchar", |
37
|
|
|
"HasFocus" => "Boolean" |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Constructor |
42
|
|
|
* |
43
|
|
|
* @param string $name |
44
|
|
|
* @param null|string $title |
45
|
|
|
* @param string $value |
46
|
|
|
*/ |
47
|
|
|
public function __construct($name, $title = null, $value = '') |
48
|
|
|
{ |
49
|
|
|
parent::__construct($name, $title, $value); |
50
|
|
|
$this->addExtraClass('password'); |
51
|
|
|
$this->setTemplate('AntonyThorpe\Knockout\KnockoutTextField'); |
52
|
|
|
$this->observable = 'password'; |
53
|
|
|
$this->setAttribute('spellcheck', 'false'); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|