Go to the source code of this file.
|
| base () |
| Example showing how groups can be used to attach transformation and constraints on multiple fields at once. More...
|
|
◆ base()
Example showing how groups can be used to attach transformation and constraints on multiple fields at once.
Note that groups do not have a defined way of outputting validations errors. This is context dependant.
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 = $DIC->refinery();
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()->group(
34 [ $number_input->withLabel(
"Left"), $number_input->withLabel(
"Right")]
36 ->withAdditionalTransformation($sum)
37 ->withAdditionalTransformation($equal_ten);
40 $form = $ui->input()->container()->form()->standard(
'#', [
"custom_group" => $group]);
43 if ($request->getMethod() ==
"POST") {
46 $form = $form->withRequest($request);
47 $group = $form->getInputs()[
"custom_group"];
48 if ($group->getError()) {
60 "<pre>" . print_r(
$result,
true) .
"</pre><br/>" .
61 $renderer->render($form);