ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
Textarea.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2017 Jesús lópez <lopez@leifos.com> Extended GPL, see docs/LICENSE */
4
6
10use ILIAS\Data\Factory as DataFactory;
11
15class Textarea extends Input implements C\Input\Field\Textarea
16{
18
19 protected $max_limit;
20 protected $min_limit;
21
25 public function __construct(
26 DataFactory $data_factory,
27 \ILIAS\Refinery\Factory $refinery,
28 $label,
29 $byline
30 ) {
31 parent::__construct($data_factory, $refinery, $label, $byline);
32 $this->setAdditionalTransformation(
33 $refinery->string()->stripTags()
34 );
35 }
36
42 public function withMaxLimit($max_limit)
43 {
44 $clone = $this->withAdditionalTransformation(
45 $this->refinery->string()->hasMaxLength($max_limit)
46 );
47 $clone->max_limit = $max_limit;
48 return $clone;
49 }
50
55 public function getMaxLimit()
56 {
57 return $this->max_limit;
58 }
59
65 public function withMinLimit($min_limit)
66 {
67 $clone = $this->withAdditionalTransformation(
68 $this->refinery->string()->hasMinLength($min_limit)
69 );
70 $clone->min_limit = $min_limit;
71 return $clone;
72 }
73
78 public function getMinLimit()
79 {
80 return $this->min_limit;
81 }
82
86 protected function isClientSideValueOk($value) : bool
87 {
88 return is_string($value);
89 }
90
91
95 protected function getConstraintForRequirement()
96 {
97 if ($this->min_limit) {
98 return $this->refinery->string()->hasMinLength($this->min_limit);
99 }
100 return $this->refinery->string()->hasMinLength(1);
101 }
102
106 public function isLimited()
107 {
108 if ($this->min_limit || $this->max_limit) {
109 return true;
110 }
111 return false;
112 }
113
117 public function getUpdateOnLoadCode() : \Closure
118 {
119 return function ($id) {
120 $code = "$('#$id').on('input', function(event) {
121 il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());
122 });
123 il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());";
124 return $code;
125 };
126 }
127}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
withMinLimit($min_limit)
set minimum number of characters
Definition: Textarea.php:65
getMaxLimit()
get maximum limit of characters
Definition: Textarea.php:55
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event,...
Definition: Textarea.php:117
getMinLimit()
get minimum limit of characters
Definition: Textarea.php:78
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, $label, $byline)
Definition: Textarea.php:25
withMaxLimit($max_limit)
set maximum number of characters
Definition: Textarea.php:42
This describes commonalities between all inputs.
Definition: Input.php:32
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the content of the input.
This describes Textarea inputs.
Definition: Textarea.php:13
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
Class ChatMainBarProvider \MainMenu\Provider.