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