ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables 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  private bool $complex = false;
36 
37  public function __construct(
38  DataFactory $data_factory,
40  string $label,
41  ?string $byline
42  ) {
43  parent::__construct($data_factory, $refinery, $label, $byline);
44 
48  $trafo_numericOrNull = $this->refinery->byTrying([
49  $this->refinery->kindlyTo()->null(),
50  $this->refinery->kindlyTo()->int()
51  ])
52  ->withProblemBuilder(fn ($txt) => $txt("ui_numeric_only"));
53 
54  $this->setAdditionalTransformation($trafo_numericOrNull);
55  }
56 
60  protected function isClientSideValueOk($value): bool
61  {
62  return is_numeric($value) || $value === "" || $value === null;
63  }
64 
68  protected function getConstraintForRequirement(): ?Constraint
69  {
70  if ($this->requirement_constraint !== null) {
71  return $this->requirement_constraint;
72  }
73 
74  return $this->refinery->numeric()->isNumeric();
75  }
76 
80  public function getUpdateOnLoadCode(): Closure
81  {
82  return fn ($id) => "$('#$id').on('input', function(event) {
83  il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());
84  });
85  il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());";
86  }
87 
91  public function isComplex(): bool
92  {
93  return $this->complex;
94  }
95 }
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 file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:62
This implements the numeric input.
Definition: Numeric.php:33
$txt
Definition: error.php:13
withProblemBuilder(callable $builder)
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: Numeric.php:80
__construct(Container $dic, ilPlugin $plugin)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This describes inputs that can be used in forms.
Definition: FormInput.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Refinery Factory $refinery