ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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{
37
38 protected ?int $max_limit = null;
39
40 protected ?int $min_limit = null;
41
42 private bool $strip_tags_from_input = true;
43
47 public function __construct(
48 DataFactory $data_factory,
50 string $label,
51 ?string $byline
52 ) {
53 parent::__construct($data_factory, $refinery, $label, $byline);
54 }
55
59 public function withMaxLimit(int $max_limit): C\Input\Field\Textarea
60 {
64 $clone = $this->withAdditionalTransformation(
65 $this->refinery->string()->hasMaxLength($max_limit)
66 );
67 $clone->max_limit = $max_limit;
68 return $clone;
69 }
70
75 public function getMaxLimit(): ?int
76 {
77 return $this->max_limit;
78 }
79
83 public function withMinLimit(int $min_limit): C\Input\Field\Textarea
84 {
88 $clone = $this->withAdditionalTransformation(
89 $this->refinery->string()->hasMinLength($min_limit)
90 );
91 $clone->min_limit = $min_limit;
92 return $clone;
93 }
94
99 public function getMinLimit(): ?int
100 {
101 return $this->min_limit;
102 }
103
107 protected function isClientSideValueOk($value): bool
108 {
109 return is_string($value);
110 }
111
116 {
117 if ($this->requirement_constraint !== null) {
118 return $this->requirement_constraint;
119 }
120
121 if ($this->min_limit) {
122 return $this->refinery->string()->hasMinLength($this->min_limit);
123 }
124 return $this->refinery->string()->hasMinLength(1);
125 }
126
130 public function isLimited(): bool
131 {
132 return $this->min_limit > 0 || $this->max_limit > 0;
133 }
134
138 public function getUpdateOnLoadCode(): Closure
139 {
140 return fn($id) => "$('#$id').on('input', function(event) {
141 il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());
142 });
143 il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());";
144 }
145
149 public function getOperations(): Generator
150 {
151 if ($this->strip_tags_from_input) {
152 yield $this->refinery->custom()->transformation(fn($v) => strip_tags($v));
153 }
154 yield from parent::getOperations();
155 }
156
160 public function withoutStripTags(): C\Input\Field\Textarea
161 {
162 $clone = clone $this;
163 $clone->strip_tags_from_input = false;
164 return $clone;
165 }
166}
$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:75
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event,...
Definition: Textarea.php:138
getMinLimit()
get minimum limit of characters
Definition: Textarea.php:99
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, ?string $byline)
Definition: Textarea.php:47
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.