ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
Numeric.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Timon Amstutz <timon.amstutz@ilub.unibe.ch> Extended GPL, see
4 docs/LICENSE */
5 
7 
10 use ILIAS\UI\Component as C;
12 
16 class Numeric extends Input implements C\Input\Field\Numeric
17 {
21  private $complex = false;
22 
31  public function __construct(
32  DataFactory $data_factory,
33  \ILIAS\Refinery\Factory $refinery,
34  $label,
35  $byline
36  ) {
37  parent::__construct($data_factory, $refinery, $label, $byline);
38 
42  $trafo_numericOrNull = $this->refinery->byTrying([
43  $this->refinery->kindlyTo()->null(),
44  $this->refinery->kindlyTo()->int()
45  ])
46  ->withProblemBuilder(function ($txt, $value) {
47  return $txt("ui_numeric_only");
48  });
49 
50  $this->setAdditionalTransformation($trafo_numericOrNull);
51  }
52 
56  protected function isClientSideValueOk($value) : bool
57  {
58  return is_numeric($value) || $value === "" || $value === null;
59  }
60 
64  protected function getConstraintForRequirement()
65  {
66  return $this->refinery->kindlyTo()->int();
67  }
68 
72  public function getUpdateOnLoadCode() : \Closure
73  {
74  return function ($id) {
75  $code = "$('#$id').on('input', function(event) {
76  il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());
77  });
78  il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());";
79  return $code;
80  };
81  }
82 
86  public function isComplex() : bool
87  {
88  return $this->complex;
89  }
90 }
This describes numeric inputs.
Definition: Numeric.php:11
Class ChatMainBarProvider .
Builds data types.
Definition: Factory.php:19
$txt
Definition: error.php:13
withProblemBuilder(callable $builder)
__construct(Container $dic, ilPlugin $plugin)
__construct($a_client_id=0)
Constructor setup ILIAS global object public.