ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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);
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) {
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
Interface Observer Contains several chained tasks and infos about them.
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 current or future content.
Definition: Input.php:145
Factory for Date Formats.
Definition: Factory.php:26
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes Textarea inputs.
Definition: Textarea.php:28
setAdditionalTransformation(Transformation $trafo)
Apply a transformation to the current or future content.
Definition: Input.php:158
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
__construct(Container $dic, ilPlugin $plugin)
This describes commonalities between all inputs.
Definition: Input.php:46
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