ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Numeric.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Data\Factory as DataFactory;
27use Closure;
29
33class 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);
44 $this->setAdditionalTransformation($this->getStandardTrafoInt());
45 }
46
50 protected function isClientSideValueOk($value): bool
51 {
52 return is_numeric($value) || $value === "" || $value === null;
53 }
54
59 {
60 if ($this->requirement_constraint !== null) {
61 return $this->requirement_constraint;
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}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:36
Transform values according to custom configuration.
This implements the numeric input.
Definition: Numeric.php:34
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event,...
Definition: Numeric.php:70
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, ?string $byline)
Definition: Numeric.php:37
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
A transformation is a function from one datatype to another.
This describes inputs that can be used in forms.
Definition: FormInput.php:33
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.