Go to the source code of this file.
|
| base () |
| Example showing how sections can be used to attach transformation and constraints on multiple fields at once. More...
|
|
◆ base()
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.
Definition at line 7 of file base.php.
References $data, $DIC, $lng, and $result.
11 $ui = $DIC->ui()->factory();
12 $lng = $DIC->language();
13 $renderer = $DIC->ui()->renderer();
14 $request = $DIC->http()->request();
15 $data = new \ILIAS\Data\Factory();
16 $refinery = new \ILIAS\Refinery\Factory(
$data,
$lng);
19 $sum = $refinery->custom()->transformation(
function ($vs) {
24 $equal_ten = $refinery->custom()->constraint(
function ($v) {
26 },
"The sum must equal ten");
29 $number_input = $ui->input()->field()->numeric(
"number",
"Put in a number.");
33 $group = $ui->input()->field()->section(
34 [ $number_input->withLabel(
"Left"), $number_input->withLabel(
"Right")],
36 "Left and Right must equal 10" 38 ->withAdditionalTransformation($sum)
39 ->withAdditionalTransformation($equal_ten);
42 $form = $ui->input()->container()->form()->standard(
'#', [$group]);
45 if ($request->getMethod() ==
"POST") {
46 $form = $form->withRequest($request);
54 "<pre>" . print_r(
$result,
true) .
"</pre><br/>" .
55 $renderer->render($form);