ILIAS  release_7 Revision v7.30-3-g800a261c036
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;
12
16class 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}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
__construct($a_client_id=0)
Constructor setup ILIAS global object @access public.
$txt
Definition: error.php:13
A transformation is a function from one datatype to another.
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.