Example showing how disabled sections can be used to attach transformation and constraints on multiple fields at once.
7{
8
10 $ui =
$DIC->ui()->factory();
12 $renderer =
$DIC->ui()->renderer();
13 $request =
$DIC->http()->request();
14 $data = new \ILIAS\Data\Factory();
15 $refinery = new \ILIAS\Refinery\Factory(
$data,
$lng);
16
17
18 $sum = $refinery->custom()->transformation(function ($vs) {
19 list($l, $r) = $vs;
20 $s = $l + $r;
21 return $s;
22 });
23 $equal_ten = $refinery->custom()->constraint(function ($v) {
24 return $v == 10;
25 }, "The sum must equal ten");
26
27
28 $number_input = $ui->input()->field()->numeric("number", "Put in a number.")->withValue(5);
29
30
31
32 $group = $ui->input()->field()->section(
33 [ $number_input->withLabel("Left"), $number_input->withLabel("Right")],
34 "Equals 10",
35 "Left and Right must equal 10"
36 )
37 ->withAdditionalTransformation($sum)
38 ->withAdditionalTransformation($equal_ten)
39 ->withDisabled(true);
40
41
42 $form = $ui->input()->container()->form()->standard('#', [$group]);
43
44
45 if ($request->getMethod() == "POST") {
46 $form = $form->withRequest($request);
48 } else {
50 }
51
52
53 return
54 "<pre>" . print_r(
$result,
true) .
"</pre><br/>" .
55 $renderer->render($form);
56}