ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
4docs/LICENSE */
5
7
8use ILIAS\Data\Factory as DataFactory;
11
15class 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}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event,...
Definition: Numeric.php:74
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, $label, $byline)
Numeric constructor.
Definition: Numeric.php:26
$txt
Definition: error.php:13
This describes commonalities between all inputs.
Definition: Input.php:32
This describes numeric inputs.
Definition: Numeric.php:12
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.