ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Textarea.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ILIAS\Data\Factory as DataFactory;
27use Closure;
28use Generator;
29
34{
36
37 protected ?int $max_limit = null;
38
39 protected ?int $min_limit = null;
40
41 private bool $strip_tags_from_input = true;
42
46 public function __construct(
47 DataFactory $data_factory,
49 string $label,
50 ?string $byline
51 ) {
52 parent::__construct($data_factory, $refinery, $label, $byline);
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
148 public function getOperations(): Generator
149 {
150 if ($this->strip_tags_from_input) {
151 yield $this->refinery->custom()->transformation(fn($v) => strip_tags($v));
152 }
153 yield from parent::getOperations();
154 }
155
159 public function withoutStripTags(): C\Input\Field\Textarea
160 {
161 $clone = clone $this;
162 $clone->strip_tags_from_input = false;
163 return $clone;
164 }
165}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:36
This implements the textarea input.
Definition: Textarea.php:34
getMaxLimit()
get maximum limit of characters
Definition: Textarea.php:74
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event,...
Definition: Textarea.php:137
getMinLimit()
get minimum limit of characters
Definition: Textarea.php:98
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, ?string $byline)
Definition: Textarea.php:46
This implements commonalities between inputs.
Definition: Input.php:43
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
This describes inputs that can be used in forms.
Definition: FormInput.php:33
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the content of the input.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.