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, $form, $l, $lng, $r, $request, $result, and $s.
11 $ui = $DIC->ui()->factory();
12 $lng = $DIC->language();
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();
20 $sum = $trafo->custom(
function ($vs) {
25 $equal_ten = $validation->custom(
function ($v) {
27 },
"The sum must equal ten");
30 $number_input = $ui->input()->field()->numeric(
"number",
"Put in a number.");
34 $group = $ui->input()->field()->section(
35 [ $number_input->withLabel(
"Left"), $number_input->withLabel(
"Right")],
37 "Left and Right must equal 10" 39 ->withAdditionalTransformation($sum)
40 ->withAdditionalConstraint($equal_ten);
43 $DIC->ctrl()->setParameterByClass(
44 'ilsystemstyledocumentationgui',
48 $form_action = $DIC->ctrl()->getFormActionByClass(
'ilsystemstyledocumentationgui');
49 $form = $ui->input()->container()->form()->standard($form_action, [$group]);
53 &&
$request->getQueryParams()[
'example_name'] ==
'numeric_inputs') {
62 "<pre>" . print_r(
$result,
true) .
"</pre><br/>" .
63 $renderer->render(
$form);
foreach($paths as $path) $request
if(isset($_POST['submit'])) $form