ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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  protected int|float $stepsize = 1;
36 
37  public function __construct(
38  DataFactory $data_factory,
40  string $label,
41  ?string $byline
42  ) {
43  parent::__construct($data_factory, $refinery, $label, $byline);
45  }
46 
50  protected function isClientSideValueOk($value): bool
51  {
52  return is_numeric($value) || $value === "" || $value === null;
53  }
54 
58  protected function getConstraintForRequirement(): ?Constraint
59  {
60  if ($this->requirement_constraint !== null) {
62  }
63 
64  return $this->refinery->numeric()->isNumeric();
65  }
66 
70  public function getUpdateOnLoadCode(): Closure
71  {
72  return fn($id) => "$('#$id').on('input', function(event) {
73  il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());
74  });
75  il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());";
76  }
77 
81  public function isComplex(): bool
82  {
83  return false;
84  }
85 
86  public function withStepSize(int|float $stepsize = 1): self
87  {
88  $clone = clone $this;
89  $clone->stepsize = $stepsize;
90 
91  if (is_int($stepsize) && is_float($this->stepsize)) {
92  $clone->operations = [$this->getStandardTrafoInt()];
93  }
94 
95  if (is_float($stepsize) && is_int($this->stepsize)) {
96  $clone->operations = [$this->getStandardTrafoFloat()];
97  }
98  return $clone;
99  }
100 
102  {
103  return $this->refinery->byTrying([
104  $this->refinery->kindlyTo()->null(),
105  $this->refinery->kindlyTo()->int()
106  ]);
107  }
109  {
110  return $this->refinery->byTrying([
111  $this->refinery->kindlyTo()->null(),
112  $this->refinery->kindlyTo()->float()
113  ]);
114  }
115 
116  public function getStepSize(): int|float
117  {
118  return $this->stepsize;
119  }
120 
121 }
Transform values according to custom configuration.
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
setAdditionalTransformation(Transformation $trafo)
Apply a transformation to the current or future content.
Definition: Input.php:158
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, ?string $byline)
Definition: Numeric.php:37
$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