ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 
9 use ILIAS\UI\Component as C;
11 
15 class Numeric extends Input implements C\Input\Field\Numeric
16 {
26  public function __construct(
27  DataFactory $data_factory,
28  \ILIAS\Refinery\Factory $refinery,
29  $label,
30  $byline
31  ) {
32  parent::__construct($data_factory, $refinery, $label, $byline);
33 
34  $trafo_empty2null = $this->refinery->custom()->transformation(
35  function ($v) {
36  if (trim($v) === '') {
37  return null;
38  }
39  return $v;
40  },
41  ""
42  );
43  $trafo_numericOrNull = $this->refinery->logical()->logicalOr([
44  $this->refinery->numeric()->isNumeric(),
45  $this->refinery->null()
46  ])
47  ->withProblemBuilder(function ($txt, $value) {
48  return $txt("ui_numeric_only");
49  });
50 
51  $this->setAdditionalTransformation($trafo_empty2null);
52  $this->setAdditionalTransformation($trafo_numericOrNull);
53  }
54 
58  protected function isClientSideValueOk($value) : bool
59  {
60  return is_numeric($value) || $value === "" || $value === null;
61  }
62 
66  protected function getConstraintForRequirement()
67  {
68  return $this->refinery->numeric()->isNumeric();
69  }
70 
74  public function getUpdateOnLoadCode() : \Closure
75  {
76  return function ($id) {
77  $code = "$('#$id').on('input', function(event) {
78  il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());
79  });
80  il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());";
81  return $code;
82  };
83  }
84 }
This describes numeric inputs.
Definition: Numeric.php:11
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, $label, $byline)
Numeric constructor.
Definition: Numeric.php:26
Class ChatMainBarProvider .
Builds data types.
Definition: Factory.php:19
$txt
Definition: error.php:13
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;.string
Definition: Numeric.php:74
__construct(Container $dic, ilPlugin $plugin)