ILIAS  release_8 Revision v8.24
Text.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\Data\Factory as DataFactory;
26use Closure;
27
31class Text extends FormInput implements C\Input\Field\Text
32{
33 private ?int $max_length = null;
34 private bool $complex = false;
35
39 public function __construct(
40 DataFactory $data_factory,
41 \ILIAS\Refinery\Factory $refinery,
42 string $label,
43 ?string $byline
44 ) {
45 parent::__construct($data_factory, $refinery, $label, $byline);
46 $this->setAdditionalTransformation($refinery->custom()->transformation(fn ($v) => strip_tags($v)));
47 }
48
52 public function withMaxLength(int $max_length): C\Input\Field\Text
53 {
54 $clone = $this->withAdditionalTransformation(
55 $this->refinery->string()->hasMaxLength($max_length)
56 );
57 $clone->max_length = $max_length;
58
59 return $clone;
60 }
61
65 public function getMaxLength(): ?int
66 {
67 return $this->max_length;
68 }
69
73 protected function isClientSideValueOk($value): bool
74 {
75 if (!is_string($value)) {
76 return false;
77 }
78
79 if ($this->max_length !== null &&
80 strlen($value) > $this->max_length) {
81 return false;
82 }
83
84 return true;
85 }
86
91 {
92 if ($this->requirement_constraint !== null) {
93 return $this->requirement_constraint;
94 }
95
96 return $this->refinery->string()->hasMinLength(1);
97 }
98
102 public function getUpdateOnLoadCode(): Closure
103 {
104 return fn ($id) => "$('#$id').on('input', function(event) {
105 il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());
106 });
107 il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());";
108 }
109
113 public function isComplex(): bool
114 {
115 return $this->complex;
116 }
117}
$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 text input.
Definition: Text.php:32
withMaxLength(int $max_length)
@inheritDoc
Definition: Text.php:52
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event,...
Definition: Text.php:102
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, ?string $byline)
Definition: Text.php:39
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
Class ChatMainBarProvider \MainMenu\Provider.