ILIAS  release_8 Revision v8.24
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;
28
33{
35
36 protected ?int $max_limit = null;
37
38 protected ?int $min_limit = null;
39
43 public function __construct(
44 DataFactory $data_factory,
45 \ILIAS\Refinery\Factory $refinery,
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}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:21
This is a legacy support of Implementation\Component\Input\Field\Input that has been moved to Impleme...
Definition: Input.php:32
This implements the textarea input.
Definition: Textarea.php:33
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:43
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
This describes inputs that can be used in forms.
Definition: FormInput.php:32
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the content of the input.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Refinery Factory $refinery
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
Class ChatMainBarProvider \MainMenu\Provider.