Example showing how sections can be used to attach transformation and constraints on multiple fields at once.
Note that sections have a standard way of displaying constraint violations to the user.
8{
9
11 $ui =
$DIC->ui()->factory();
13 $renderer =
$DIC->ui()->renderer();
15 $data = new \ILIAS\Data\Factory();
16 $validation = new \ILIAS\Validation\Factory(
$data,
$lng);
17 $trafo = new \ILIAS\Transformation\Factory();
18
19
20 $sum = $trafo->custom(function ($vs) {
24 });
25 $equal_ten = $validation->custom(function ($v) {
26 return $v == 10;
27 }, "The sum must equal ten");
28
29
30 $number_input = $ui->input()->field()->numeric("number", "Put in a number.");
31
32
33
34 $group = $ui->input()->field()->section(
35 [ $number_input->withLabel("Left"), $number_input->withLabel("Right")],
36 "Equals 10",
37 "Left and Right must equal 10"
38 )
39 ->withAdditionalTransformation($sum)
40 ->withAdditionalConstraint($equal_ten);
41
42
43 $DIC->ctrl()->setParameterByClass(
44 'ilsystemstyledocumentationgui',
45 'example_name',
46 'numeric_inputs'
47 );
48 $form_action =
$DIC->ctrl()->getFormActionByClass(
'ilsystemstyledocumentationgui');
49 $form = $ui->input()->container()->form()->standard($form_action, [$group]);
50
51
53 &&
$request->getQueryParams()[
'example_name'] ==
'numeric_inputs') {
56 } else {
58 }
59
60
61 return
62 "<pre>" . print_r(
$result,
true) .
"</pre><br/>" .
63 $renderer->render(
$form);
64}
foreach($paths as $path) $request
if(isset($_POST['submit'])) $form