ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Numeric.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 use ILIAS\UI\Component as C;
27 use Closure;
29 
33 class Numeric extends FormInput implements C\Input\Field\Numeric
34 {
35  public function __construct(
36  DataFactory $data_factory,
38  string $label,
39  ?string $byline
40  ) {
41  parent::__construct($data_factory, $refinery, $label, $byline);
42 
46  $trafo_numericOrNull = $this->refinery->byTrying([
47  $this->refinery->kindlyTo()->null(),
48  $this->refinery->kindlyTo()->int()
49  ])
50  ->withProblemBuilder(fn($txt) => $txt("numeric_only"));
51 
52  $this->setAdditionalTransformation($trafo_numericOrNull);
53  }
54 
58  protected function isClientSideValueOk($value): bool
59  {
60  return is_numeric($value) || $value === "" || $value === null;
61  }
62 
66  protected function getConstraintForRequirement(): ?Constraint
67  {
68  if ($this->requirement_constraint !== null) {
70  }
71 
72  return $this->refinery->numeric()->isNumeric();
73  }
74 
78  public function getUpdateOnLoadCode(): Closure
79  {
80  return fn($id) => "$('#$id').on('input', function(event) {
81  il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());
82  });
83  il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());";
84  }
85 
89  public function isComplex(): bool
90  {
91  return false;
92  }
93 }
__construct(DataFactory $data_factory, Refinery $refinery, protected string $label, protected ?string $byline=null,)
Definition: FormInput.php:43
Interface Observer Contains several chained tasks and infos about them.
A constraint encodes some resrtictions on values.
Definition: Constraint.php:31
Factory for Date Formats.
Definition: Factory.php:26
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This implements the numeric input.
Definition: Numeric.php:33
$txt
Definition: error.php:31
setAdditionalTransformation(Transformation $trafo)
Apply a transformation to the current or future content.
Definition: Input.php:158
withProblemBuilder(callable $builder)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)
This describes inputs that can be used in forms.
Definition: FormInput.php:32