| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace LeKoala\FormElements; |
||||
| 4 | |||||
| 5 | use SilverStripe\Forms\TextareaField; |
||||
| 6 | use SilverStripe\View\Requirements; |
||||
| 7 | |||||
| 8 | /** |
||||
| 9 | */ |
||||
| 10 | class GrowingTextarea extends TextareaField |
||||
| 11 | { |
||||
| 12 | use BaseElement; |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 13 | |||||
| 14 | /** |
||||
| 15 | * @config |
||||
| 16 | * @var boolean |
||||
| 17 | */ |
||||
| 18 | private static $enable_requirements = true; |
||||
|
0 ignored issues
–
show
|
|||||
| 19 | |||||
| 20 | /** |
||||
| 21 | * @var boolean |
||||
| 22 | */ |
||||
| 23 | protected $trim = false; |
||||
| 24 | |||||
| 25 | public function __construct($name, $title = null, $value = '', $config = null) |
||||
|
0 ignored issues
–
show
The parameter
$config is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 26 | { |
||||
| 27 | parent::__construct($name, $title, $value); |
||||
| 28 | $this->setRows(1); |
||||
| 29 | } |
||||
| 30 | |||||
| 31 | public function Field($properties = array()) |
||||
| 32 | { |
||||
| 33 | return $this->wrapInElement('growing-textarea', $properties); |
||||
| 34 | } |
||||
| 35 | |||||
| 36 | public function setValue($value, $data = null) |
||||
| 37 | { |
||||
| 38 | parent::setValue($value, $data); |
||||
| 39 | if ($this->value) { |
||||
| 40 | $this->setRows(substr_count($this->value, "\n") + 1); |
||||
| 41 | } |
||||
| 42 | return $this; |
||||
| 43 | } |
||||
| 44 | |||||
| 45 | public static function requirements() |
||||
| 46 | { |
||||
| 47 | Requirements::javascript("lekoala/silverstripe-form-elements: client/custom-elements/growing-textarea.min.js"); |
||||
| 48 | } |
||||
| 49 | |||||
| 50 | /** |
||||
| 51 | * Get the value of trim |
||||
| 52 | */ |
||||
| 53 | public function getTrim() |
||||
| 54 | { |
||||
| 55 | return $this->getElementAttribute('data-trim'); |
||||
| 56 | } |
||||
| 57 | |||||
| 58 | /** |
||||
| 59 | * Set the value of trim |
||||
| 60 | * |
||||
| 61 | * @param bool $trim |
||||
| 62 | */ |
||||
| 63 | public function setTrim($trim) |
||||
| 64 | { |
||||
| 65 | return $this->setElementAttribute('data-trim', $trim); |
||||
| 66 | } |
||||
| 67 | } |
||||
| 68 |