ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
numeric_with_decimals.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
50{
51 global $DIC;
52 $ui = $DIC->ui()->factory();
53 $renderer = $DIC->ui()->renderer();
54 $request = $DIC->http()->request();
55 $refinery = $DIC->refinery();
56 $df = new \ILIAS\Data\Factory();
57 $query = $DIC->http()->wrapper()->query();
58 $here_uri = $df->uri($request->getUri()->__toString());
59 $url_builder = new URLBuilder($here_uri);
60 $example_namespace = ['input', 'numeric'];
61 list($url_builder, $example_name) = $url_builder->acquireParameters($example_namespace, "example_name");
62 $url_builder = $url_builder->withParameter($example_name, "decimals");
63
64
65 $number_input = $ui->input()->field()
66 ->numeric("int", "step size is 3")
67 ->withStepSize(3)
68 ->withValue(3);
69
70 $number_input2 = $ui->input()->field()
71 ->numeric("float", "step size is .2")
72 ->withStepSize(.2)
73 ->withValue(.4);
74
75 $number_input3 = $ui->input()->field()
76 ->numeric("float", "step size is .0005")
77 ->withStepSize(.0005)
78 ->withValue(.1);
79
80 $number_input4 = $ui->input()->field()
81 ->numeric("float", "step size is 111.01, initial value is 10.7")
82 ->withStepSize(111.01)
83 ->withValue(10.7);
84
85 $form_action = $url_builder->buildURI()->__toString();
86 $form = $ui->input()->container()->form()->standard(
87 $form_action,
88 [$number_input, $number_input2, $number_input3, $number_input4]
89 )
90 ->withAdditionalTransformation(
91 $refinery->custom()->transformation(
92 fn($v) => array_map(fn($val) => $val . ' (' . gettype($val) . ')', $v)
93 )
94 );
95
96 if ($query->has($example_name->getName())
97 && $query->retrieve($example_name->getName(), $refinery->custom()->transformation(fn($v) => $v === 'decimals'))
98 ) {
99 $form = $form->withRequest($request);
100 $result = $form->getData();
101 } else {
102 $result = "No result yet.";
103 }
104
105 //Return the rendered form
106 return
107 "<pre>" . print_r($result, true) . "</pre><br/>" .
108 $renderer->render($form);
109}
$renderer
global $DIC
Definition: shib_login.php:26