ILIAS  release_8 Revision v8.23
Text.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;
26 use Closure;
27 
31 class 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,
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 
90  protected function getConstraintForRequirement(): ?Constraint
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 }
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A constraint encodes some resrtictions on values.
Definition: Constraint.php:31
This implements the text input.
Definition: Text.php:31
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the content of the input.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
__construct(Container $dic, ilPlugin $plugin)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event, &#39;$id&#39;, string_value);initially "onload" andon every input change. It must pass a readable string representation of its value in parameter &#39;string_value&#39;.
Definition: Text.php:102
This describes inputs that can be used in forms.
Definition: FormInput.php:31
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, ?string $byline)
Definition: Text.php:39
Refinery Factory $refinery