ILIAS  release_8 Revision v8.24
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 private bool $complex = false;
36
37 public function __construct(
38 DataFactory $data_factory,
39 \ILIAS\Refinery\Factory $refinery,
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
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}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:21
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:80
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:62
$txt
Definition: error.php:13
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:32
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Refinery Factory $refinery
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
Class ChatMainBarProvider \MainMenu\Provider.