ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
Textarea.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\UI\Component as C;
27 use Closure;
28 
32 class Textarea extends FormInput implements C\Input\Field\Textarea
33 {
35 
36  protected ?int $max_limit = null;
37 
38  protected ?int $min_limit = null;
39 
43  public function __construct(
44  DataFactory $data_factory,
46  string $label,
47  ?string $byline
48  ) {
49  parent::__construct($data_factory, $refinery, $label, $byline);
50  $this->setAdditionalTransformation(
51  $refinery->string()->stripTags()
52  );
53  }
54 
58  public function withMaxLimit(int $max_limit): C\Input\Field\Textarea
59  {
63  $clone = $this->withAdditionalTransformation(
64  $this->refinery->string()->hasMaxLength($max_limit)
65  );
66  $clone->max_limit = $max_limit;
67  return $clone;
68  }
69 
74  public function getMaxLimit(): ?int
75  {
76  return $this->max_limit;
77  }
78 
82  public function withMinLimit(int $min_limit): C\Input\Field\Textarea
83  {
87  $clone = $this->withAdditionalTransformation(
88  $this->refinery->string()->hasMinLength($min_limit)
89  );
90  $clone->min_limit = $min_limit;
91  return $clone;
92  }
93 
98  public function getMinLimit(): ?int
99  {
100  return $this->min_limit;
101  }
102 
106  protected function isClientSideValueOk($value): bool
107  {
108  return is_string($value);
109  }
110 
115  {
116  if ($this->requirement_constraint !== null) {
117  return $this->requirement_constraint;
118  }
119 
120  if ($this->min_limit) {
121  return $this->refinery->string()->hasMinLength($this->min_limit);
122  }
123  return $this->refinery->string()->hasMinLength(1);
124  }
125 
129  public function isLimited(): bool
130  {
131  return $this->min_limit > 0 || $this->max_limit > 0;
132  }
133 
137  public function getUpdateOnLoadCode(): Closure
138  {
139  return fn ($id) => "$('#$id').on('input', function(event) {
140  il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());
141  });
142  il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());";
143  }
144 }
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, ?string $byline)
Definition: Textarea.php:43
Class ChatMainBarProvider .
This implements the textarea input.
Definition: Textarea.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
A constraint encodes some resrtictions on values.
Definition: Constraint.php:31
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the content of the input.
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event, &#39;$id&#39;, string_value);initially "onload" andon every input change. It must pass a readable string representation of its value in parameter &#39;string_value&#39;.
Definition: Textarea.php:137
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
This describes Textarea inputs.
Definition: Textarea.php:28
__construct(Container $dic, ilPlugin $plugin)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This describes inputs that can be used in forms.
Definition: FormInput.php:31
getMinLimit()
get minimum limit of characters
Definition: Textarea.php:98
getMaxLimit()
get maximum limit of characters
Definition: Textarea.php:74
Refinery Factory $refinery